repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Wedeto/DB | src/Model.php | Model.destruct | public function destruct()
{
$this->_id = [];
$this->_source_db = null;
$this->_record = [];
$this->_changed = [];
return $this;
} | php | public function destruct()
{
$this->_id = [];
$this->_source_db = null;
$this->_record = [];
$this->_changed = [];
return $this;
} | [
"public",
"function",
"destruct",
"(",
")",
"{",
"$",
"this",
"->",
"_id",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_source_db",
"=",
"null",
";",
"$",
"this",
"->",
"_record",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_changed",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Remove the data from this object, after removal
@return Wedeto\DB\Model Prvides fluent interface | [
"Remove",
"the",
"data",
"from",
"this",
"object",
"after",
"removal"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Model.php#L251-L258 | train |
Wedeto/DB | src/Model.php | Model.getField | public function getField(string $field)
{
if (isset($this->_record[$field]))
return $this->_record[$field];
return null;
} | php | public function getField(string $field)
{
if (isset($this->_record[$field]))
return $this->_record[$field];
return null;
} | [
"public",
"function",
"getField",
"(",
"string",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_record",
"[",
"$",
"field",
"]",
")",
")",
"return",
"$",
"this",
"->",
"_record",
"[",
"$",
"field",
"]",
";",
"return",
"null",
";",
"}"
] | Get the value for a field of this record.
@param string $field The name of the field to get
@return mixed The value of this field | [
"Get",
"the",
"value",
"for",
"a",
"field",
"of",
"this",
"record",
"."
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Model.php#L277-L282 | train |
Wedeto/DB | src/Model.php | Model.setField | public function setField(string $field, $value)
{
if (isset($this->_record[$field]) && $this->_record[$field] === $value)
return;
$db = $this->getDB();
$dao = $db->getDAO(static::class);
$columns = $dao->getColumns();
if (!isset($columns[$field]))
throw new InvalidValueException("Field $field does not exist!");
$pkey = $dao->getPrimaryKey();
$coldef = $columns[$field];
if (static::validate($coldef, $value))
{
$this->_record[$field] = $value;
$this->_changed[$field] = true;
if (isset($pkey[$field]))
$this->_id[$field] = $value;
// Synchronize value of local properties
if (property_exists($this, $field))
$this->$field = $value;
}
return $this;
} | php | public function setField(string $field, $value)
{
if (isset($this->_record[$field]) && $this->_record[$field] === $value)
return;
$db = $this->getDB();
$dao = $db->getDAO(static::class);
$columns = $dao->getColumns();
if (!isset($columns[$field]))
throw new InvalidValueException("Field $field does not exist!");
$pkey = $dao->getPrimaryKey();
$coldef = $columns[$field];
if (static::validate($coldef, $value))
{
$this->_record[$field] = $value;
$this->_changed[$field] = true;
if (isset($pkey[$field]))
$this->_id[$field] = $value;
// Synchronize value of local properties
if (property_exists($this, $field))
$this->$field = $value;
}
return $this;
} | [
"public",
"function",
"setField",
"(",
"string",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_record",
"[",
"$",
"field",
"]",
")",
"&&",
"$",
"this",
"->",
"_record",
"[",
"$",
"field",
"]",
"===",
"$",
"value",
")",
"return",
";",
"$",
"db",
"=",
"$",
"this",
"->",
"getDB",
"(",
")",
";",
"$",
"dao",
"=",
"$",
"db",
"->",
"getDAO",
"(",
"static",
"::",
"class",
")",
";",
"$",
"columns",
"=",
"$",
"dao",
"->",
"getColumns",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"columns",
"[",
"$",
"field",
"]",
")",
")",
"throw",
"new",
"InvalidValueException",
"(",
"\"Field $field does not exist!\"",
")",
";",
"$",
"pkey",
"=",
"$",
"dao",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"coldef",
"=",
"$",
"columns",
"[",
"$",
"field",
"]",
";",
"if",
"(",
"static",
"::",
"validate",
"(",
"$",
"coldef",
",",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"_record",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"_changed",
"[",
"$",
"field",
"]",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"pkey",
"[",
"$",
"field",
"]",
")",
")",
"$",
"this",
"->",
"_id",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"// Synchronize value of local properties",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"field",
")",
")",
"$",
"this",
"->",
"$",
"field",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set a field to a new value. The value will be validated first by
calling validate.
@param string $field The field to retrieve
@param mixed $value The value to set it to.
@return Wedeto\DB\DAO Provides fluent interface. | [
"Set",
"a",
"field",
"to",
"a",
"new",
"value",
".",
"The",
"value",
"will",
"be",
"validated",
"first",
"by",
"calling",
"validate",
"."
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Model.php#L305-L332 | train |
Wedeto/DB | src/Model.php | Model.validate | public static function validate(Column $coldef, $value)
{
$field = $coldef->getName();
try
{
$valid = $coldef->validate($value);
}
catch (InvalidValueException $e)
{
$rep = WF::str($value);
throw new InvalidValueException("Field $field cannot be set to $rep: {$e->getMessage()}");
}
return $valid;
} | php | public static function validate(Column $coldef, $value)
{
$field = $coldef->getName();
try
{
$valid = $coldef->validate($value);
}
catch (InvalidValueException $e)
{
$rep = WF::str($value);
throw new InvalidValueException("Field $field cannot be set to $rep: {$e->getMessage()}");
}
return $valid;
} | [
"public",
"static",
"function",
"validate",
"(",
"Column",
"$",
"coldef",
",",
"$",
"value",
")",
"{",
"$",
"field",
"=",
"$",
"coldef",
"->",
"getName",
"(",
")",
";",
"try",
"{",
"$",
"valid",
"=",
"$",
"coldef",
"->",
"validate",
"(",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"InvalidValueException",
"$",
"e",
")",
"{",
"$",
"rep",
"=",
"WF",
"::",
"str",
"(",
"$",
"value",
")",
";",
"throw",
"new",
"InvalidValueException",
"(",
"\"Field $field cannot be set to $rep: {$e->getMessage()}\"",
")",
";",
"}",
"return",
"$",
"valid",
";",
"}"
] | Validate a value for the field before setting it. This method is called
from the setField method before updating the value. You can override
this to add validators. Be sure to call the super validator to validate
the base field to match the column definition.
@param Column $coldef The column
@param mixed $value The value to validate
@return bool True if the value is valid
@throws InvalidValueException When the value is not acceptable | [
"Validate",
"a",
"value",
"for",
"the",
"field",
"before",
"setting",
"it",
".",
"This",
"method",
"is",
"called",
"from",
"the",
"setField",
"method",
"before",
"updating",
"the",
"value",
".",
"You",
"can",
"override",
"this",
"to",
"add",
"validators",
".",
"Be",
"sure",
"to",
"call",
"the",
"super",
"validator",
"to",
"validate",
"the",
"base",
"field",
"to",
"match",
"the",
"column",
"definition",
"."
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Model.php#L399-L413 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/caching/stores/AbstractCacheStore.php | AbstractCacheStore.storageFormat | protected function storageFormat($key, $data, $ttl)
{
$start = time();
$expire = $start + $ttl;
return array('key' => $key, 'value' => $data, 'duration' => $ttl, 'created' => $start, 'expires' => $expire);
} | php | protected function storageFormat($key, $data, $ttl)
{
$start = time();
$expire = $start + $ttl;
return array('key' => $key, 'value' => $data, 'duration' => $ttl, 'created' => $start, 'expires' => $expire);
} | [
"protected",
"function",
"storageFormat",
"(",
"$",
"key",
",",
"$",
"data",
",",
"$",
"ttl",
")",
"{",
"$",
"start",
"=",
"time",
"(",
")",
";",
"$",
"expire",
"=",
"$",
"start",
"+",
"$",
"ttl",
";",
"return",
"array",
"(",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"data",
",",
"'duration'",
"=>",
"$",
"ttl",
",",
"'created'",
"=>",
"$",
"start",
",",
"'expires'",
"=>",
"$",
"expire",
")",
";",
"}"
] | Defines the array that will be used to store data.
Changing this will require updating all functions that also fetch data.
At no point after this function is called should the data be manipulated,
only inserted directly into cache.
@param string $key Key name
@param string $data Data to store
@param int $ttl Duration in seconds for data to live in cache
@return array An that will be stored in the cache. | [
"Defines",
"the",
"array",
"that",
"will",
"be",
"used",
"to",
"store",
"data",
".",
"Changing",
"this",
"will",
"require",
"updating",
"all",
"functions",
"that",
"also",
"fetch",
"data",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/AbstractCacheStore.php#L33-L39 | train |
brunschgi/TerrificComposerBundle | Controller/ModuleController.php | ModuleController.detailsAction | public function detailsAction(Request $request, $module, $template, $skins)
{
$fullModule = null;
try {
$moduleManager = $this->get('terrific.composer.module.manager');
$fullModule = $moduleManager->getModuleByName($module);
// prepare the parameter for module rendering
$template = $fullModule->getTemplateByName($template)->getPath();
if($skins) {
$skins = explode(',', $skins);
}
else {
$skins = array();
}
}
catch (\Exception $e) {
$logger = $this->get('logger');
$logger->err($e->getMessage());
$this->get('session')->setFlash('notice', 'Module could not be found: ' . $e->getMessage());
}
// decide whether to render the layout or not (ajax = without layout | default = with layout)
if($request->isXmlHttpRequest()) {
// render the module without layout
return $this->render('TerrificComposerBundle:Module:details.ajax.html.twig', array('module' => $module, 'template' => $template, 'skins' => $skins));
}
else {
// render the module with layout
return $this->render('TerrificComposerBundle:Module:details.html.twig', array('layout' => $moduleManager->getModuleLayout(),'module' => $module, 'template' => $template, 'skins' => $skins));
}
} | php | public function detailsAction(Request $request, $module, $template, $skins)
{
$fullModule = null;
try {
$moduleManager = $this->get('terrific.composer.module.manager');
$fullModule = $moduleManager->getModuleByName($module);
// prepare the parameter for module rendering
$template = $fullModule->getTemplateByName($template)->getPath();
if($skins) {
$skins = explode(',', $skins);
}
else {
$skins = array();
}
}
catch (\Exception $e) {
$logger = $this->get('logger');
$logger->err($e->getMessage());
$this->get('session')->setFlash('notice', 'Module could not be found: ' . $e->getMessage());
}
// decide whether to render the layout or not (ajax = without layout | default = with layout)
if($request->isXmlHttpRequest()) {
// render the module without layout
return $this->render('TerrificComposerBundle:Module:details.ajax.html.twig', array('module' => $module, 'template' => $template, 'skins' => $skins));
}
else {
// render the module with layout
return $this->render('TerrificComposerBundle:Module:details.html.twig', array('layout' => $moduleManager->getModuleLayout(),'module' => $module, 'template' => $template, 'skins' => $skins));
}
} | [
"public",
"function",
"detailsAction",
"(",
"Request",
"$",
"request",
",",
"$",
"module",
",",
"$",
"template",
",",
"$",
"skins",
")",
"{",
"$",
"fullModule",
"=",
"null",
";",
"try",
"{",
"$",
"moduleManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'terrific.composer.module.manager'",
")",
";",
"$",
"fullModule",
"=",
"$",
"moduleManager",
"->",
"getModuleByName",
"(",
"$",
"module",
")",
";",
"// prepare the parameter for module rendering",
"$",
"template",
"=",
"$",
"fullModule",
"->",
"getTemplateByName",
"(",
"$",
"template",
")",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"skins",
")",
"{",
"$",
"skins",
"=",
"explode",
"(",
"','",
",",
"$",
"skins",
")",
";",
"}",
"else",
"{",
"$",
"skins",
"=",
"array",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
";",
"$",
"logger",
"->",
"err",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"setFlash",
"(",
"'notice'",
",",
"'Module could not be found: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"// decide whether to render the layout or not (ajax = without layout | default = with layout)",
"if",
"(",
"$",
"request",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"// render the module without layout",
"return",
"$",
"this",
"->",
"render",
"(",
"'TerrificComposerBundle:Module:details.ajax.html.twig'",
",",
"array",
"(",
"'module'",
"=>",
"$",
"module",
",",
"'template'",
"=>",
"$",
"template",
",",
"'skins'",
"=>",
"$",
"skins",
")",
")",
";",
"}",
"else",
"{",
"// render the module with layout",
"return",
"$",
"this",
"->",
"render",
"(",
"'TerrificComposerBundle:Module:details.html.twig'",
",",
"array",
"(",
"'layout'",
"=>",
"$",
"moduleManager",
"->",
"getModuleLayout",
"(",
")",
",",
"'module'",
"=>",
"$",
"module",
",",
"'template'",
"=>",
"$",
"template",
",",
"'skins'",
"=>",
"$",
"skins",
")",
")",
";",
"}",
"}"
] | Display the details of a terrific module.
@Route("/module/details/{module}/{template}/{skins}", defaults={"template" = null, "skins" = null}, name = "composer_module_details")
@Template() | [
"Display",
"the",
"details",
"of",
"a",
"terrific",
"module",
"."
] | 6eef4ace887c19ef166ab6654de385bc1ffbf5f1 | https://github.com/brunschgi/TerrificComposerBundle/blob/6eef4ace887c19ef166ab6654de385bc1ffbf5f1/Controller/ModuleController.php#L36-L70 | train |
brunschgi/TerrificComposerBundle | Controller/ModuleController.php | ModuleController.createAction | public function createAction(Request $request)
{
if ($this->get('session')->has('module')) {
// get the last module from the session to fill some defaults for the new one
$tmpModule = $this->get('session')->get('module');
// setup a fresh module object
$module = new Module();
$module->setStyle($tmpModule->getStyle());
}
else {
// setup a fresh module object
$module = new Module();
// fill it with some defaults
$module->setStyle('less');
}
// create form
$form = $this->createForm(new ModuleType(), $module);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// set default templates
$module->addTemplate(strtolower($module->getName()));
// save the module in the session
$this->get('session')->set('module', $module);
// create the module in the filesystem
try {
$moduleManager = $this->get('terrific.composer.module.manager');
$moduleManager->createModule($module);
$this->get('session')->setFlash('notice', 'Module ' . ucfirst($module->getName()) . ' created successfully');
}
catch (\Exception $e) {
$logger = $this->get('logger');
$logger->err($e->getMessage());
$this->get('session')->setFlash('notice', 'Module could not be created: ' . $e->getMessage());
}
if ($request->get('addskin', false)) {
// redirect to the add skin form
return $this->redirect($this->generateUrl('composer_add_skin'));
}
else {
// redirect to the create module form
return $this->redirect($this->generateUrl('composer_create_module'));
}
}
}
return array('form' => $form->createView());
} | php | public function createAction(Request $request)
{
if ($this->get('session')->has('module')) {
// get the last module from the session to fill some defaults for the new one
$tmpModule = $this->get('session')->get('module');
// setup a fresh module object
$module = new Module();
$module->setStyle($tmpModule->getStyle());
}
else {
// setup a fresh module object
$module = new Module();
// fill it with some defaults
$module->setStyle('less');
}
// create form
$form = $this->createForm(new ModuleType(), $module);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// set default templates
$module->addTemplate(strtolower($module->getName()));
// save the module in the session
$this->get('session')->set('module', $module);
// create the module in the filesystem
try {
$moduleManager = $this->get('terrific.composer.module.manager');
$moduleManager->createModule($module);
$this->get('session')->setFlash('notice', 'Module ' . ucfirst($module->getName()) . ' created successfully');
}
catch (\Exception $e) {
$logger = $this->get('logger');
$logger->err($e->getMessage());
$this->get('session')->setFlash('notice', 'Module could not be created: ' . $e->getMessage());
}
if ($request->get('addskin', false)) {
// redirect to the add skin form
return $this->redirect($this->generateUrl('composer_add_skin'));
}
else {
// redirect to the create module form
return $this->redirect($this->generateUrl('composer_create_module'));
}
}
}
return array('form' => $form->createView());
} | [
"public",
"function",
"createAction",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"has",
"(",
"'module'",
")",
")",
"{",
"// get the last module from the session to fill some defaults for the new one",
"$",
"tmpModule",
"=",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"get",
"(",
"'module'",
")",
";",
"// setup a fresh module object",
"$",
"module",
"=",
"new",
"Module",
"(",
")",
";",
"$",
"module",
"->",
"setStyle",
"(",
"$",
"tmpModule",
"->",
"getStyle",
"(",
")",
")",
";",
"}",
"else",
"{",
"// setup a fresh module object",
"$",
"module",
"=",
"new",
"Module",
"(",
")",
";",
"// fill it with some defaults",
"$",
"module",
"->",
"setStyle",
"(",
"'less'",
")",
";",
"}",
"// create form",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ModuleType",
"(",
")",
",",
"$",
"module",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"'POST'",
")",
"{",
"$",
"form",
"->",
"bindRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"// set default templates",
"$",
"module",
"->",
"addTemplate",
"(",
"strtolower",
"(",
"$",
"module",
"->",
"getName",
"(",
")",
")",
")",
";",
"// save the module in the session",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"set",
"(",
"'module'",
",",
"$",
"module",
")",
";",
"// create the module in the filesystem",
"try",
"{",
"$",
"moduleManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'terrific.composer.module.manager'",
")",
";",
"$",
"moduleManager",
"->",
"createModule",
"(",
"$",
"module",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"setFlash",
"(",
"'notice'",
",",
"'Module '",
".",
"ucfirst",
"(",
"$",
"module",
"->",
"getName",
"(",
")",
")",
".",
"' created successfully'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
";",
"$",
"logger",
"->",
"err",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"setFlash",
"(",
"'notice'",
",",
"'Module could not be created: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'addskin'",
",",
"false",
")",
")",
"{",
"// redirect to the add skin form",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'composer_add_skin'",
")",
")",
";",
"}",
"else",
"{",
"// redirect to the create module form",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'composer_create_module'",
")",
")",
";",
"}",
"}",
"}",
"return",
"array",
"(",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
")",
";",
"}"
] | Creates a terrific module.
@Route("/module/create", name="composer_create_module")
@Template()
@param Request $request
@return Response | [
"Creates",
"a",
"terrific",
"module",
"."
] | 6eef4ace887c19ef166ab6654de385bc1ffbf5f1 | https://github.com/brunschgi/TerrificComposerBundle/blob/6eef4ace887c19ef166ab6654de385bc1ffbf5f1/Controller/ModuleController.php#L81-L138 | train |
brunschgi/TerrificComposerBundle | Controller/ModuleController.php | ModuleController.addskinAction | public function addskinAction(Request $request)
{
// setup a fresh skin and module object
$skin = new Skin();
$module = new Module();
if ($this->get('session')->has('module')) {
// get the last module from the session to fill some additional defaults for the new skin
$tmpModule = $this->get('session')->get('module');
$skin->setModule($tmpModule->getName());
$skin->setStyle($tmpModule->getStyle());
}
else {
// fill it with some defaults
$skin->setStyle('less');
}
// create form
$form = $this->createForm(new SkinType(), $skin);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// create the skin in the filesystem
try {
$moduleManager = $this->get('terrific.composer.module.manager');
$moduleManager->createSkin($skin);
$module->setStyle($skin->getStyle());
$module->setName($skin->getModule());
$this->get('session')->set('module', $module);
$this->get('session')->setFlash('notice', 'Skin ' . ucfirst($skin->getName()) . ' for Module ' . ucfirst($module->getName()) . ' created successfully');
}
catch (\Exception $e) {
$logger = $this->get('logger');
$logger->err($e->getMessage());
$this->get('session')->setFlash('notice', 'Skin could not be created: ' . $e->getMessage());
}
return $this->redirect($this->generateUrl('composer_add_skin'));
}
}
return array('form' => $form->createView());
} | php | public function addskinAction(Request $request)
{
// setup a fresh skin and module object
$skin = new Skin();
$module = new Module();
if ($this->get('session')->has('module')) {
// get the last module from the session to fill some additional defaults for the new skin
$tmpModule = $this->get('session')->get('module');
$skin->setModule($tmpModule->getName());
$skin->setStyle($tmpModule->getStyle());
}
else {
// fill it with some defaults
$skin->setStyle('less');
}
// create form
$form = $this->createForm(new SkinType(), $skin);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// create the skin in the filesystem
try {
$moduleManager = $this->get('terrific.composer.module.manager');
$moduleManager->createSkin($skin);
$module->setStyle($skin->getStyle());
$module->setName($skin->getModule());
$this->get('session')->set('module', $module);
$this->get('session')->setFlash('notice', 'Skin ' . ucfirst($skin->getName()) . ' for Module ' . ucfirst($module->getName()) . ' created successfully');
}
catch (\Exception $e) {
$logger = $this->get('logger');
$logger->err($e->getMessage());
$this->get('session')->setFlash('notice', 'Skin could not be created: ' . $e->getMessage());
}
return $this->redirect($this->generateUrl('composer_add_skin'));
}
}
return array('form' => $form->createView());
} | [
"public",
"function",
"addskinAction",
"(",
"Request",
"$",
"request",
")",
"{",
"// setup a fresh skin and module object",
"$",
"skin",
"=",
"new",
"Skin",
"(",
")",
";",
"$",
"module",
"=",
"new",
"Module",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"has",
"(",
"'module'",
")",
")",
"{",
"// get the last module from the session to fill some additional defaults for the new skin",
"$",
"tmpModule",
"=",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"get",
"(",
"'module'",
")",
";",
"$",
"skin",
"->",
"setModule",
"(",
"$",
"tmpModule",
"->",
"getName",
"(",
")",
")",
";",
"$",
"skin",
"->",
"setStyle",
"(",
"$",
"tmpModule",
"->",
"getStyle",
"(",
")",
")",
";",
"}",
"else",
"{",
"// fill it with some defaults",
"$",
"skin",
"->",
"setStyle",
"(",
"'less'",
")",
";",
"}",
"// create form",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"SkinType",
"(",
")",
",",
"$",
"skin",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"'POST'",
")",
"{",
"$",
"form",
"->",
"bindRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"// create the skin in the filesystem",
"try",
"{",
"$",
"moduleManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'terrific.composer.module.manager'",
")",
";",
"$",
"moduleManager",
"->",
"createSkin",
"(",
"$",
"skin",
")",
";",
"$",
"module",
"->",
"setStyle",
"(",
"$",
"skin",
"->",
"getStyle",
"(",
")",
")",
";",
"$",
"module",
"->",
"setName",
"(",
"$",
"skin",
"->",
"getModule",
"(",
")",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"set",
"(",
"'module'",
",",
"$",
"module",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"setFlash",
"(",
"'notice'",
",",
"'Skin '",
".",
"ucfirst",
"(",
"$",
"skin",
"->",
"getName",
"(",
")",
")",
".",
"' for Module '",
".",
"ucfirst",
"(",
"$",
"module",
"->",
"getName",
"(",
")",
")",
".",
"' created successfully'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"get",
"(",
"'logger'",
")",
";",
"$",
"logger",
"->",
"err",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"setFlash",
"(",
"'notice'",
",",
"'Skin could not be created: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'composer_add_skin'",
")",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
")",
";",
"}"
] | Adds a skin to the module.
@Route("/module/addskin", name="composer_add_skin")
@Template()
@param Request $request
@return Response | [
"Adds",
"a",
"skin",
"to",
"the",
"module",
"."
] | 6eef4ace887c19ef166ab6654de385bc1ffbf5f1 | https://github.com/brunschgi/TerrificComposerBundle/blob/6eef4ace887c19ef166ab6654de385bc1ffbf5f1/Controller/ModuleController.php#L149-L196 | train |
phpffcms/ffcms-core | src/Network/Request/RouteMapFeatures.php | RouteMapFeatures.runRouteBinding | private function runRouteBinding(): void
{
// calculated depend of language
$pathway = $this->getPathInfo();
/** @var array $routing */
$routing = App::$Properties->getAll('Routing');
// try to work with static aliases
if (Any::isArray($routing) && isset($routing['Alias'], $routing['Alias'][env_name])) {
$pathway = $this->findStaticAliases($routing['Alias'][env_name], $pathway);
}
$this->setPathdata(explode('/', trim($pathway, '/')));
// set default controller and action for undefined data
if (!$this->action) {
$this->action = 'Index';
}
// empty or contains backslashes? set to main
if (!$this->controller || Str::contains('\\', $this->controller)) {
$this->controller = 'Main';
}
// find callback injection in routing configs (calculated in App::run())
if (Any::isArray($routing) && isset($routing['Callback'], $routing['Callback'][env_name])) {
$this->findDynamicCallbacks($routing['Callback'][env_name], $this->controller);
}
} | php | private function runRouteBinding(): void
{
// calculated depend of language
$pathway = $this->getPathInfo();
/** @var array $routing */
$routing = App::$Properties->getAll('Routing');
// try to work with static aliases
if (Any::isArray($routing) && isset($routing['Alias'], $routing['Alias'][env_name])) {
$pathway = $this->findStaticAliases($routing['Alias'][env_name], $pathway);
}
$this->setPathdata(explode('/', trim($pathway, '/')));
// set default controller and action for undefined data
if (!$this->action) {
$this->action = 'Index';
}
// empty or contains backslashes? set to main
if (!$this->controller || Str::contains('\\', $this->controller)) {
$this->controller = 'Main';
}
// find callback injection in routing configs (calculated in App::run())
if (Any::isArray($routing) && isset($routing['Callback'], $routing['Callback'][env_name])) {
$this->findDynamicCallbacks($routing['Callback'][env_name], $this->controller);
}
} | [
"private",
"function",
"runRouteBinding",
"(",
")",
":",
"void",
"{",
"// calculated depend of language",
"$",
"pathway",
"=",
"$",
"this",
"->",
"getPathInfo",
"(",
")",
";",
"/** @var array $routing */",
"$",
"routing",
"=",
"App",
"::",
"$",
"Properties",
"->",
"getAll",
"(",
"'Routing'",
")",
";",
"// try to work with static aliases",
"if",
"(",
"Any",
"::",
"isArray",
"(",
"$",
"routing",
")",
"&&",
"isset",
"(",
"$",
"routing",
"[",
"'Alias'",
"]",
",",
"$",
"routing",
"[",
"'Alias'",
"]",
"[",
"env_name",
"]",
")",
")",
"{",
"$",
"pathway",
"=",
"$",
"this",
"->",
"findStaticAliases",
"(",
"$",
"routing",
"[",
"'Alias'",
"]",
"[",
"env_name",
"]",
",",
"$",
"pathway",
")",
";",
"}",
"$",
"this",
"->",
"setPathdata",
"(",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"pathway",
",",
"'/'",
")",
")",
")",
";",
"// set default controller and action for undefined data",
"if",
"(",
"!",
"$",
"this",
"->",
"action",
")",
"{",
"$",
"this",
"->",
"action",
"=",
"'Index'",
";",
"}",
"// empty or contains backslashes? set to main",
"if",
"(",
"!",
"$",
"this",
"->",
"controller",
"||",
"Str",
"::",
"contains",
"(",
"'\\\\'",
",",
"$",
"this",
"->",
"controller",
")",
")",
"{",
"$",
"this",
"->",
"controller",
"=",
"'Main'",
";",
"}",
"// find callback injection in routing configs (calculated in App::run())",
"if",
"(",
"Any",
"::",
"isArray",
"(",
"$",
"routing",
")",
"&&",
"isset",
"(",
"$",
"routing",
"[",
"'Callback'",
"]",
",",
"$",
"routing",
"[",
"'Callback'",
"]",
"[",
"env_name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"findDynamicCallbacks",
"(",
"$",
"routing",
"[",
"'Callback'",
"]",
"[",
"env_name",
"]",
",",
"$",
"this",
"->",
"controller",
")",
";",
"}",
"}"
] | Build static and dynamic path aliases for working set
@return void | [
"Build",
"static",
"and",
"dynamic",
"path",
"aliases",
"for",
"working",
"set"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Network/Request/RouteMapFeatures.php#L26-L54 | train |
phpffcms/ffcms-core | src/Network/Request/RouteMapFeatures.php | RouteMapFeatures.findStaticAliases | private function findStaticAliases(?array $map = null, ?string $pathway = null): ?string
{
if (!$map) {
return $pathway;
}
// current pathway is found as "old path" (or alias target). Make redirect to new pathway.
if (Arr::in($pathway, $map)) {
// find "new path" as binding uri slug
$binding = array_search($pathway, $map, true);
// build url to redirection
$url = $this->getSchemeAndHttpHost() . $this->getBasePath() . '/';
if (App::$Properties->get('multiLanguage')) {
$url .= $this->language . '/';
}
$url .= ltrim($binding, '/');
$redirect = new RedirectResponse($url);
$redirect->send();
exit();
}
// current pathway request is equal to path alias. Set alias to property.
if (array_key_exists($pathway, $map)) {
$pathway = $map[$pathway];
$this->aliasPathTarget = $pathway;
}
return $pathway;
} | php | private function findStaticAliases(?array $map = null, ?string $pathway = null): ?string
{
if (!$map) {
return $pathway;
}
// current pathway is found as "old path" (or alias target). Make redirect to new pathway.
if (Arr::in($pathway, $map)) {
// find "new path" as binding uri slug
$binding = array_search($pathway, $map, true);
// build url to redirection
$url = $this->getSchemeAndHttpHost() . $this->getBasePath() . '/';
if (App::$Properties->get('multiLanguage')) {
$url .= $this->language . '/';
}
$url .= ltrim($binding, '/');
$redirect = new RedirectResponse($url);
$redirect->send();
exit();
}
// current pathway request is equal to path alias. Set alias to property.
if (array_key_exists($pathway, $map)) {
$pathway = $map[$pathway];
$this->aliasPathTarget = $pathway;
}
return $pathway;
} | [
"private",
"function",
"findStaticAliases",
"(",
"?",
"array",
"$",
"map",
"=",
"null",
",",
"?",
"string",
"$",
"pathway",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"!",
"$",
"map",
")",
"{",
"return",
"$",
"pathway",
";",
"}",
"// current pathway is found as \"old path\" (or alias target). Make redirect to new pathway.",
"if",
"(",
"Arr",
"::",
"in",
"(",
"$",
"pathway",
",",
"$",
"map",
")",
")",
"{",
"// find \"new path\" as binding uri slug",
"$",
"binding",
"=",
"array_search",
"(",
"$",
"pathway",
",",
"$",
"map",
",",
"true",
")",
";",
"// build url to redirection",
"$",
"url",
"=",
"$",
"this",
"->",
"getSchemeAndHttpHost",
"(",
")",
".",
"$",
"this",
"->",
"getBasePath",
"(",
")",
".",
"'/'",
";",
"if",
"(",
"App",
"::",
"$",
"Properties",
"->",
"get",
"(",
"'multiLanguage'",
")",
")",
"{",
"$",
"url",
".=",
"$",
"this",
"->",
"language",
".",
"'/'",
";",
"}",
"$",
"url",
".=",
"ltrim",
"(",
"$",
"binding",
",",
"'/'",
")",
";",
"$",
"redirect",
"=",
"new",
"RedirectResponse",
"(",
"$",
"url",
")",
";",
"$",
"redirect",
"->",
"send",
"(",
")",
";",
"exit",
"(",
")",
";",
"}",
"// current pathway request is equal to path alias. Set alias to property.",
"if",
"(",
"array_key_exists",
"(",
"$",
"pathway",
",",
"$",
"map",
")",
")",
"{",
"$",
"pathway",
"=",
"$",
"map",
"[",
"$",
"pathway",
"]",
";",
"$",
"this",
"->",
"aliasPathTarget",
"=",
"$",
"pathway",
";",
"}",
"return",
"$",
"pathway",
";",
"}"
] | Prepare static pathway aliasing for routing
@param array|null $map
@param string|null $pathway
@return string|null | [
"Prepare",
"static",
"pathway",
"aliasing",
"for",
"routing"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Network/Request/RouteMapFeatures.php#L62-L91 | train |
phpffcms/ffcms-core | src/Network/Request/RouteMapFeatures.php | RouteMapFeatures.findDynamicCallbacks | private function findDynamicCallbacks(array $map = null, ?string $controller = null): void
{
if (!$map) {
return;
}
// try to find global callback for this controller slug
if (array_key_exists($controller, $map)) {
$class = (string)$map[$controller];
if (!Str::likeEmpty($class)) {
$this->callbackClass = $class;
}
}
} | php | private function findDynamicCallbacks(array $map = null, ?string $controller = null): void
{
if (!$map) {
return;
}
// try to find global callback for this controller slug
if (array_key_exists($controller, $map)) {
$class = (string)$map[$controller];
if (!Str::likeEmpty($class)) {
$this->callbackClass = $class;
}
}
} | [
"private",
"function",
"findDynamicCallbacks",
"(",
"array",
"$",
"map",
"=",
"null",
",",
"?",
"string",
"$",
"controller",
"=",
"null",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"map",
")",
"{",
"return",
";",
"}",
"// try to find global callback for this controller slug",
"if",
"(",
"array_key_exists",
"(",
"$",
"controller",
",",
"$",
"map",
")",
")",
"{",
"$",
"class",
"=",
"(",
"string",
")",
"$",
"map",
"[",
"$",
"controller",
"]",
";",
"if",
"(",
"!",
"Str",
"::",
"likeEmpty",
"(",
"$",
"class",
")",
")",
"{",
"$",
"this",
"->",
"callbackClass",
"=",
"$",
"class",
";",
"}",
"}",
"}"
] | Prepare dynamic callback data for routing
@param array|null $map
@param string|null $controller
@return void | [
"Prepare",
"dynamic",
"callback",
"data",
"for",
"routing"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Network/Request/RouteMapFeatures.php#L99-L112 | train |
rollerworks/search-core | SearchConditionSerializer.php | SearchConditionSerializer.serialize | public function serialize(SearchCondition $searchCondition): array
{
$setName = $searchCondition->getFieldSet()->getSetName();
return [$setName, serialize($searchCondition->getValuesGroup())];
} | php | public function serialize(SearchCondition $searchCondition): array
{
$setName = $searchCondition->getFieldSet()->getSetName();
return [$setName, serialize($searchCondition->getValuesGroup())];
} | [
"public",
"function",
"serialize",
"(",
"SearchCondition",
"$",
"searchCondition",
")",
":",
"array",
"{",
"$",
"setName",
"=",
"$",
"searchCondition",
"->",
"getFieldSet",
"(",
")",
"->",
"getSetName",
"(",
")",
";",
"return",
"[",
"$",
"setName",
",",
"serialize",
"(",
"$",
"searchCondition",
"->",
"getValuesGroup",
"(",
")",
")",
"]",
";",
"}"
] | Serialize a SearchCondition.
The returned value is an array you can safely serialize yourself.
This is not done already because storing a serialized SearchCondition
in a php session would serialize the serialized result again.
Caution: The FieldSet must be loadable from the factory.
@return array [FieldSet-name, serialized ValuesGroup object] | [
"Serialize",
"a",
"SearchCondition",
"."
] | 6b5671b8c4d6298906ded768261b0a59845140fb | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/SearchConditionSerializer.php#L46-L51 | train |
rollerworks/search-core | SearchConditionSerializer.php | SearchConditionSerializer.unserialize | public function unserialize(array $searchCondition): SearchCondition
{
if (2 !== \count($searchCondition) || !isset($searchCondition[0], $searchCondition[1])) {
throw new InvalidArgumentException(
'Serialized search condition must be exactly two values [FieldSet-name, serialized ValuesGroup].'
);
}
$fieldSet = $this->searchFactory->createFieldSet($searchCondition[0]);
// FIXME This needs safe serialzing with error handling
if (false === $group = unserialize($searchCondition[1])) {
throw new InvalidArgumentException('Unable to unserialize invalid value.');
}
return new SearchCondition($fieldSet, $group);
} | php | public function unserialize(array $searchCondition): SearchCondition
{
if (2 !== \count($searchCondition) || !isset($searchCondition[0], $searchCondition[1])) {
throw new InvalidArgumentException(
'Serialized search condition must be exactly two values [FieldSet-name, serialized ValuesGroup].'
);
}
$fieldSet = $this->searchFactory->createFieldSet($searchCondition[0]);
// FIXME This needs safe serialzing with error handling
if (false === $group = unserialize($searchCondition[1])) {
throw new InvalidArgumentException('Unable to unserialize invalid value.');
}
return new SearchCondition($fieldSet, $group);
} | [
"public",
"function",
"unserialize",
"(",
"array",
"$",
"searchCondition",
")",
":",
"SearchCondition",
"{",
"if",
"(",
"2",
"!==",
"\\",
"count",
"(",
"$",
"searchCondition",
")",
"||",
"!",
"isset",
"(",
"$",
"searchCondition",
"[",
"0",
"]",
",",
"$",
"searchCondition",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Serialized search condition must be exactly two values [FieldSet-name, serialized ValuesGroup].'",
")",
";",
"}",
"$",
"fieldSet",
"=",
"$",
"this",
"->",
"searchFactory",
"->",
"createFieldSet",
"(",
"$",
"searchCondition",
"[",
"0",
"]",
")",
";",
"// FIXME This needs safe serialzing with error handling",
"if",
"(",
"false",
"===",
"$",
"group",
"=",
"unserialize",
"(",
"$",
"searchCondition",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Unable to unserialize invalid value.'",
")",
";",
"}",
"return",
"new",
"SearchCondition",
"(",
"$",
"fieldSet",
",",
"$",
"group",
")",
";",
"}"
] | Unserialize a serialized SearchCondition.
@param array $searchCondition [FieldSet-name, serialized ValuesGroup object]
@throws InvalidArgumentException when serialized SearchCondition is invalid
(invalid structure or failed to unserialize) | [
"Unserialize",
"a",
"serialized",
"SearchCondition",
"."
] | 6b5671b8c4d6298906ded768261b0a59845140fb | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/SearchConditionSerializer.php#L61-L77 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/URLHelper.php | URLHelper.getCurrentFullHostString | public static function getCurrentFullHostString() {
$hostString = $_SERVER["HTTPS"] ? "https" : "http";
$hostString .= "://";
$hostString .= $_SERVER["HTTP_HOST"];
$hostString .= $_SERVER["SERVER_PORT"] != 80 ? ":" . $_SERVER["SERVER_PORT"] : "";
return $hostString;
} | php | public static function getCurrentFullHostString() {
$hostString = $_SERVER["HTTPS"] ? "https" : "http";
$hostString .= "://";
$hostString .= $_SERVER["HTTP_HOST"];
$hostString .= $_SERVER["SERVER_PORT"] != 80 ? ":" . $_SERVER["SERVER_PORT"] : "";
return $hostString;
} | [
"public",
"static",
"function",
"getCurrentFullHostString",
"(",
")",
"{",
"$",
"hostString",
"=",
"$",
"_SERVER",
"[",
"\"HTTPS\"",
"]",
"?",
"\"https\"",
":",
"\"http\"",
";",
"$",
"hostString",
".=",
"\"://\"",
";",
"$",
"hostString",
".=",
"$",
"_SERVER",
"[",
"\"HTTP_HOST\"",
"]",
";",
"$",
"hostString",
".=",
"$",
"_SERVER",
"[",
"\"SERVER_PORT\"",
"]",
"!=",
"80",
"?",
"\":\"",
".",
"$",
"_SERVER",
"[",
"\"SERVER_PORT\"",
"]",
":",
"\"\"",
";",
"return",
"$",
"hostString",
";",
"}"
] | Return the current full host string for the current request including protocol and ports etc. | [
"Return",
"the",
"current",
"full",
"host",
"string",
"for",
"the",
"current",
"request",
"including",
"protocol",
"and",
"ports",
"etc",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/URLHelper.php#L42-L52 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/URLHelper.php | URLHelper.getPartialURLFromSegment | public function getPartialURLFromSegment($segmentIdx) {
$partialURL = "";
for ($i = $segmentIdx; $i < sizeof($this->segments); $i++) {
$partialURL .= (($i > $segmentIdx) ? "/" : "") . $this->segments [$i];
}
return $partialURL;
} | php | public function getPartialURLFromSegment($segmentIdx) {
$partialURL = "";
for ($i = $segmentIdx; $i < sizeof($this->segments); $i++) {
$partialURL .= (($i > $segmentIdx) ? "/" : "") . $this->segments [$i];
}
return $partialURL;
} | [
"public",
"function",
"getPartialURLFromSegment",
"(",
"$",
"segmentIdx",
")",
"{",
"$",
"partialURL",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"segmentIdx",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"this",
"->",
"segments",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"partialURL",
".=",
"(",
"(",
"$",
"i",
">",
"$",
"segmentIdx",
")",
"?",
"\"/\"",
":",
"\"\"",
")",
".",
"$",
"this",
"->",
"segments",
"[",
"$",
"i",
"]",
";",
"}",
"return",
"$",
"partialURL",
";",
"}"
] | Get a partial string version of this url object starting from a particular segment
@return string | [
"Get",
"a",
"partial",
"string",
"version",
"of",
"this",
"url",
"object",
"starting",
"from",
"a",
"particular",
"segment"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/URLHelper.php#L86-L95 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/URLHelper.php | URLHelper.getQueryParametersArray | public function getQueryParametersArray() {
$queryString = $this->getQueryString();
if (strlen($queryString) == 0) return array();
$splitQuery = explode("&", substr($queryString, 1));
$returnedParams = array();
foreach ($splitQuery as $param) {
$splitParam = explode("=", $param);
if (sizeof($splitParam) == 2) $returnedParams [$splitParam [0]] = $splitParam [1];
}
return $returnedParams;
} | php | public function getQueryParametersArray() {
$queryString = $this->getQueryString();
if (strlen($queryString) == 0) return array();
$splitQuery = explode("&", substr($queryString, 1));
$returnedParams = array();
foreach ($splitQuery as $param) {
$splitParam = explode("=", $param);
if (sizeof($splitParam) == 2) $returnedParams [$splitParam [0]] = $splitParam [1];
}
return $returnedParams;
} | [
"public",
"function",
"getQueryParametersArray",
"(",
")",
"{",
"$",
"queryString",
"=",
"$",
"this",
"->",
"getQueryString",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"queryString",
")",
"==",
"0",
")",
"return",
"array",
"(",
")",
";",
"$",
"splitQuery",
"=",
"explode",
"(",
"\"&\"",
",",
"substr",
"(",
"$",
"queryString",
",",
"1",
")",
")",
";",
"$",
"returnedParams",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"splitQuery",
"as",
"$",
"param",
")",
"{",
"$",
"splitParam",
"=",
"explode",
"(",
"\"=\"",
",",
"$",
"param",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"splitParam",
")",
"==",
"2",
")",
"$",
"returnedParams",
"[",
"$",
"splitParam",
"[",
"0",
"]",
"]",
"=",
"$",
"splitParam",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"returnedParams",
";",
"}"
] | Get all query parameters contained within this URL as an associative array.
@return array | [
"Get",
"all",
"query",
"parameters",
"contained",
"within",
"this",
"URL",
"as",
"an",
"associative",
"array",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/URLHelper.php#L165-L179 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/URLHelper.php | URLHelper.processURL | private function processURL($url) {
// Clean up special characters in url params
$url = str_replace("%20", " ", $url);
// Store a private copy for use later
$this->url = URLHelper::$testURL == null ? $url : URLHelper::$testURL;
// Split it on protocol first if required.
if (substr($url, 0, 4) == "http") {
$splitProtocol = explode("://", $url);
$requestSection = sizeof($splitProtocol) > 1 ? $splitProtocol [1] : $splitProtocol [0];
$requestSection = substr($requestSection, strpos($requestSection, "/"));
} else {
$requestSection = $url;
}
$this->requestURI = $requestSection;
// Now split it on question mark for query if required.
$splitQuestionMark = explode("?", $requestSection);
$queryStripped = $splitQuestionMark [0];
// Now ensure no trailing or leading slash.
if (substr($queryStripped, 0, 1) == '/') $queryStripped = substr($queryStripped, 1);
if (substr($queryStripped, strlen($queryStripped) - 1) == '/') $queryStripped = substr($queryStripped, 0, strlen($queryStripped) - 1);
// Now simply set the segments array to be the split on "/"
$this->segments = explode("/", $queryStripped);
} | php | private function processURL($url) {
// Clean up special characters in url params
$url = str_replace("%20", " ", $url);
// Store a private copy for use later
$this->url = URLHelper::$testURL == null ? $url : URLHelper::$testURL;
// Split it on protocol first if required.
if (substr($url, 0, 4) == "http") {
$splitProtocol = explode("://", $url);
$requestSection = sizeof($splitProtocol) > 1 ? $splitProtocol [1] : $splitProtocol [0];
$requestSection = substr($requestSection, strpos($requestSection, "/"));
} else {
$requestSection = $url;
}
$this->requestURI = $requestSection;
// Now split it on question mark for query if required.
$splitQuestionMark = explode("?", $requestSection);
$queryStripped = $splitQuestionMark [0];
// Now ensure no trailing or leading slash.
if (substr($queryStripped, 0, 1) == '/') $queryStripped = substr($queryStripped, 1);
if (substr($queryStripped, strlen($queryStripped) - 1) == '/') $queryStripped = substr($queryStripped, 0, strlen($queryStripped) - 1);
// Now simply set the segments array to be the split on "/"
$this->segments = explode("/", $queryStripped);
} | [
"private",
"function",
"processURL",
"(",
"$",
"url",
")",
"{",
"// Clean up special characters in url params",
"$",
"url",
"=",
"str_replace",
"(",
"\"%20\"",
",",
"\" \"",
",",
"$",
"url",
")",
";",
"// Store a private copy for use later",
"$",
"this",
"->",
"url",
"=",
"URLHelper",
"::",
"$",
"testURL",
"==",
"null",
"?",
"$",
"url",
":",
"URLHelper",
"::",
"$",
"testURL",
";",
"// Split it on protocol first if required.",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"4",
")",
"==",
"\"http\"",
")",
"{",
"$",
"splitProtocol",
"=",
"explode",
"(",
"\"://\"",
",",
"$",
"url",
")",
";",
"$",
"requestSection",
"=",
"sizeof",
"(",
"$",
"splitProtocol",
")",
">",
"1",
"?",
"$",
"splitProtocol",
"[",
"1",
"]",
":",
"$",
"splitProtocol",
"[",
"0",
"]",
";",
"$",
"requestSection",
"=",
"substr",
"(",
"$",
"requestSection",
",",
"strpos",
"(",
"$",
"requestSection",
",",
"\"/\"",
")",
")",
";",
"}",
"else",
"{",
"$",
"requestSection",
"=",
"$",
"url",
";",
"}",
"$",
"this",
"->",
"requestURI",
"=",
"$",
"requestSection",
";",
"// Now split it on question mark for query if required.",
"$",
"splitQuestionMark",
"=",
"explode",
"(",
"\"?\"",
",",
"$",
"requestSection",
")",
";",
"$",
"queryStripped",
"=",
"$",
"splitQuestionMark",
"[",
"0",
"]",
";",
"// Now ensure no trailing or leading slash.",
"if",
"(",
"substr",
"(",
"$",
"queryStripped",
",",
"0",
",",
"1",
")",
"==",
"'/'",
")",
"$",
"queryStripped",
"=",
"substr",
"(",
"$",
"queryStripped",
",",
"1",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"queryStripped",
",",
"strlen",
"(",
"$",
"queryStripped",
")",
"-",
"1",
")",
"==",
"'/'",
")",
"$",
"queryStripped",
"=",
"substr",
"(",
"$",
"queryStripped",
",",
"0",
",",
"strlen",
"(",
"$",
"queryStripped",
")",
"-",
"1",
")",
";",
"// Now simply set the segments array to be the split on \"/\"",
"$",
"this",
"->",
"segments",
"=",
"explode",
"(",
"\"/\"",
",",
"$",
"queryStripped",
")",
";",
"}"
] | off query parameters too. | [
"off",
"query",
"parameters",
"too",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/URLHelper.php#L185-L214 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.addInheritedAttributes | private function addInheritedAttributes(ClassMetadata $subClass, ClassMetadata $parentClass)
{
$propertyFactory = new PropertyMetadataFactory($subClass);
foreach ($parentClass->propertyMetadata as $attributeName => $parentMapping) {
//in case of inheritance from superclass, otherwise this would be caught by the mapping driver:
if ($subClass->isEmbeddedDocument && $parentMapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET) {
throw MappingException::addToSetOnEmbeddedDocument($subClass->name, $parentMapping->name);
}
$mapping = $propertyFactory->createInherited($parentClass, $parentMapping);
$subClass->addAttributeMapping($mapping);
}
} | php | private function addInheritedAttributes(ClassMetadata $subClass, ClassMetadata $parentClass)
{
$propertyFactory = new PropertyMetadataFactory($subClass);
foreach ($parentClass->propertyMetadata as $attributeName => $parentMapping) {
//in case of inheritance from superclass, otherwise this would be caught by the mapping driver:
if ($subClass->isEmbeddedDocument && $parentMapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET) {
throw MappingException::addToSetOnEmbeddedDocument($subClass->name, $parentMapping->name);
}
$mapping = $propertyFactory->createInherited($parentClass, $parentMapping);
$subClass->addAttributeMapping($mapping);
}
} | [
"private",
"function",
"addInheritedAttributes",
"(",
"ClassMetadata",
"$",
"subClass",
",",
"ClassMetadata",
"$",
"parentClass",
")",
"{",
"$",
"propertyFactory",
"=",
"new",
"PropertyMetadataFactory",
"(",
"$",
"subClass",
")",
";",
"foreach",
"(",
"$",
"parentClass",
"->",
"propertyMetadata",
"as",
"$",
"attributeName",
"=>",
"$",
"parentMapping",
")",
"{",
"//in case of inheritance from superclass, otherwise this would be caught by the mapping driver:",
"if",
"(",
"$",
"subClass",
"->",
"isEmbeddedDocument",
"&&",
"$",
"parentMapping",
"->",
"strategy",
"===",
"PropertyMetadata",
"::",
"STORAGE_STRATEGY_ADD_TO_SET",
")",
"{",
"throw",
"MappingException",
"::",
"addToSetOnEmbeddedDocument",
"(",
"$",
"subClass",
"->",
"name",
",",
"$",
"parentMapping",
"->",
"name",
")",
";",
"}",
"$",
"mapping",
"=",
"$",
"propertyFactory",
"->",
"createInherited",
"(",
"$",
"parentClass",
",",
"$",
"parentMapping",
")",
";",
"$",
"subClass",
"->",
"addAttributeMapping",
"(",
"$",
"mapping",
")",
";",
"}",
"}"
] | Adds inherited attributes to the subclass mapping.
@param ClassMetadata $subClass
@param ClassMetadata $parentClass
@throws MappingException | [
"Adds",
"inherited",
"attributes",
"to",
"the",
"subclass",
"mapping",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadataFactory.php#L58-L72 | train |
erenmustafaozdal/laravel-modules-base | src/Services/CollectionService.php | CollectionService.renderAncestorsAndSelf | public function renderAncestorsAndSelf($items, $glue = '/', $keys = ['name'])
{
$items = $items->map(function($item,$key) use($keys, $glue)
{
$ancSelf = $item->ancestorsAndSelf()->get();
$result = [ 'id' => $item->id];
foreach ($keys as $k) {
$plucks = $ancSelf->pluck($k);
$plucks->pop();
$result['parent_' . $k] = $plucks->implode($glue);
$result[$k] = $item->$k;
}
return $result;
});
$sortedGroups = $items->groupBy('parent_' . $keys[0])->map(function($item) use($keys)
{
return $item->sortBy(function ($item, $key) use($keys) {
return str_slug($item[$keys[0]]);
});
});
$result = [];
foreach($sortedGroups as $group) {
$result = array_merge_recursive($result,$group->all());
}
return $result;
} | php | public function renderAncestorsAndSelf($items, $glue = '/', $keys = ['name'])
{
$items = $items->map(function($item,$key) use($keys, $glue)
{
$ancSelf = $item->ancestorsAndSelf()->get();
$result = [ 'id' => $item->id];
foreach ($keys as $k) {
$plucks = $ancSelf->pluck($k);
$plucks->pop();
$result['parent_' . $k] = $plucks->implode($glue);
$result[$k] = $item->$k;
}
return $result;
});
$sortedGroups = $items->groupBy('parent_' . $keys[0])->map(function($item) use($keys)
{
return $item->sortBy(function ($item, $key) use($keys) {
return str_slug($item[$keys[0]]);
});
});
$result = [];
foreach($sortedGroups as $group) {
$result = array_merge_recursive($result,$group->all());
}
return $result;
} | [
"public",
"function",
"renderAncestorsAndSelf",
"(",
"$",
"items",
",",
"$",
"glue",
"=",
"'/'",
",",
"$",
"keys",
"=",
"[",
"'name'",
"]",
")",
"{",
"$",
"items",
"=",
"$",
"items",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
",",
"$",
"key",
")",
"use",
"(",
"$",
"keys",
",",
"$",
"glue",
")",
"{",
"$",
"ancSelf",
"=",
"$",
"item",
"->",
"ancestorsAndSelf",
"(",
")",
"->",
"get",
"(",
")",
";",
"$",
"result",
"=",
"[",
"'id'",
"=>",
"$",
"item",
"->",
"id",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"k",
")",
"{",
"$",
"plucks",
"=",
"$",
"ancSelf",
"->",
"pluck",
"(",
"$",
"k",
")",
";",
"$",
"plucks",
"->",
"pop",
"(",
")",
";",
"$",
"result",
"[",
"'parent_'",
".",
"$",
"k",
"]",
"=",
"$",
"plucks",
"->",
"implode",
"(",
"$",
"glue",
")",
";",
"$",
"result",
"[",
"$",
"k",
"]",
"=",
"$",
"item",
"->",
"$",
"k",
";",
"}",
"return",
"$",
"result",
";",
"}",
")",
";",
"$",
"sortedGroups",
"=",
"$",
"items",
"->",
"groupBy",
"(",
"'parent_'",
".",
"$",
"keys",
"[",
"0",
"]",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"keys",
")",
"{",
"return",
"$",
"item",
"->",
"sortBy",
"(",
"function",
"(",
"$",
"item",
",",
"$",
"key",
")",
"use",
"(",
"$",
"keys",
")",
"{",
"return",
"str_slug",
"(",
"$",
"item",
"[",
"$",
"keys",
"[",
"0",
"]",
"]",
")",
";",
"}",
")",
";",
"}",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sortedGroups",
"as",
"$",
"group",
")",
"{",
"$",
"result",
"=",
"array_merge_recursive",
"(",
"$",
"result",
",",
"$",
"group",
"->",
"all",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | ancestors and self render and get
@param Collection $items
@param string $glue
@param array $keys
@return array | [
"ancestors",
"and",
"self",
"render",
"and",
"get"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Services/CollectionService.php#L30-L55 | train |
zodream/database | src/Manager.php | Manager.setConfigs | public function setConfigs(array $args) {
if (!is_array(current($args))) {
$args = [
$this->currentName => $args
];
}
foreach ($args as $key => $item) {
if (array_key_exists($key, $this->configs)) {
$this->configs[$key] = array_merge($this->configs[$key], $item);
} else {
$this->configs[$key] = $item;
}
}
return $this;
} | php | public function setConfigs(array $args) {
if (!is_array(current($args))) {
$args = [
$this->currentName => $args
];
}
foreach ($args as $key => $item) {
if (array_key_exists($key, $this->configs)) {
$this->configs[$key] = array_merge($this->configs[$key], $item);
} else {
$this->configs[$key] = $item;
}
}
return $this;
} | [
"public",
"function",
"setConfigs",
"(",
"array",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"current",
"(",
"$",
"args",
")",
")",
")",
"{",
"$",
"args",
"=",
"[",
"$",
"this",
"->",
"currentName",
"=>",
"$",
"args",
"]",
";",
"}",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"configs",
")",
")",
"{",
"$",
"this",
"->",
"configs",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"configs",
"[",
"$",
"key",
"]",
",",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"configs",
"[",
"$",
"key",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | ADD 2D ARRAY
@param array $args
@return $this | [
"ADD",
"2D",
"ARRAY"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Manager.php#L25-L39 | train |
zodream/database | src/Manager.php | Manager.getEngine | public function getEngine($name = null) {
if (is_null($name)) {
$name = $this->getCurrentName();
}
if (array_key_exists($name, $this->engines)) {
return $this->engines[$name];
}
if (!$this->hasConfig($name)) {
throw new \InvalidArgumentException(
sprintf(
__('%s DOES NOT HAVE CONFIG!')
, $name)
);
}
$engine = $this->addEngine($name, $this->getConfig($name));
$this->changeEngineEvent($engine);
return $engine;
} | php | public function getEngine($name = null) {
if (is_null($name)) {
$name = $this->getCurrentName();
}
if (array_key_exists($name, $this->engines)) {
return $this->engines[$name];
}
if (!$this->hasConfig($name)) {
throw new \InvalidArgumentException(
sprintf(
__('%s DOES NOT HAVE CONFIG!')
, $name)
);
}
$engine = $this->addEngine($name, $this->getConfig($name));
$this->changeEngineEvent($engine);
return $engine;
} | [
"public",
"function",
"getEngine",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getCurrentName",
"(",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"engines",
")",
")",
"{",
"return",
"$",
"this",
"->",
"engines",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasConfig",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"__",
"(",
"'%s DOES NOT HAVE CONFIG!'",
")",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"engine",
"=",
"$",
"this",
"->",
"addEngine",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"getConfig",
"(",
"$",
"name",
")",
")",
";",
"$",
"this",
"->",
"changeEngineEvent",
"(",
"$",
"engine",
")",
";",
"return",
"$",
"engine",
";",
"}"
] | GET DATABASE ENGINE
@param string $name
@return mixed
@throws \Exception | [
"GET",
"DATABASE",
"ENGINE"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Manager.php#L73-L90 | train |
pryley/castor-framework | src/Container.php | Container.make | public function make( $abstract )
{
$service = isset( $this->services[$abstract] )
? $this->services[$abstract]
: $this->addNamespace( $abstract );
if( is_callable( $service )) {
return call_user_func_array( $service, [$this] );
}
if( is_object( $service )) {
return $service;
}
return $this->resolve( $service );
} | php | public function make( $abstract )
{
$service = isset( $this->services[$abstract] )
? $this->services[$abstract]
: $this->addNamespace( $abstract );
if( is_callable( $service )) {
return call_user_func_array( $service, [$this] );
}
if( is_object( $service )) {
return $service;
}
return $this->resolve( $service );
} | [
"public",
"function",
"make",
"(",
"$",
"abstract",
")",
"{",
"$",
"service",
"=",
"isset",
"(",
"$",
"this",
"->",
"services",
"[",
"$",
"abstract",
"]",
")",
"?",
"$",
"this",
"->",
"services",
"[",
"$",
"abstract",
"]",
":",
"$",
"this",
"->",
"addNamespace",
"(",
"$",
"abstract",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"service",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"service",
",",
"[",
"$",
"this",
"]",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"service",
")",
")",
"{",
"return",
"$",
"service",
";",
"}",
"return",
"$",
"this",
"->",
"resolve",
"(",
"$",
"service",
")",
";",
"}"
] | Resolve the given type from the container.
Allow unbound aliases that omit the root namespace
i.e. 'Controller' translates to 'GeminiLabs\Castor\Controller'
@param mixed $abstract
@return mixed | [
"Resolve",
"the",
"given",
"type",
"from",
"the",
"container",
".",
"Allow",
"unbound",
"aliases",
"that",
"omit",
"the",
"root",
"namespace",
"i",
".",
"e",
".",
"Controller",
"translates",
"to",
"GeminiLabs",
"\\",
"Castor",
"\\",
"Controller"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Container.php#L70-L84 | train |
squareproton/Bond | src/Bond/RecordManager/Task/NormalityCollection/Persist.php | Persist.additionalSavingTasks | protected function additionalSavingTasks( Pg $pg, $simulate = false, array &$ignoreList = array(), $action = self::ACTION_OBJECT )
{
// additional saving tasks?
$repository = $this->recordManager->entityManager->getRepository( $this->object->class );
$normality = $repository->normality;
// links
if( isset( $normality['persist']['links'] ) ) {
foreach( $normality['persist']['links'] as $link ) {
$links = $repository->linksGet( $this->object, $link, Repository::CHANGED + Base::INITIAL );
// save links
if( $task = $this->recordManager->getTask( $links, Task::PERSIST, false ) ) {
$task->execute( $pg, $simulate, $ignoreList, self::ACTION_OBJECT );
}
}
}
// references
if( isset( $normality['persist']['references'] ) ) {
foreach( $normality['persist']['references'] as $reference ) {
$references = $repository->referencesGet( $this->object, $reference, Repository::CHANGED );
// save links
if( $references and $task = $this->recordManager->getTask( $references, Task::PERSIST, false ) ) {
$task->execute( $pg, $simulate, $ignoreList, self::ACTION_OBJECT );
}
}
}
return true;
} | php | protected function additionalSavingTasks( Pg $pg, $simulate = false, array &$ignoreList = array(), $action = self::ACTION_OBJECT )
{
// additional saving tasks?
$repository = $this->recordManager->entityManager->getRepository( $this->object->class );
$normality = $repository->normality;
// links
if( isset( $normality['persist']['links'] ) ) {
foreach( $normality['persist']['links'] as $link ) {
$links = $repository->linksGet( $this->object, $link, Repository::CHANGED + Base::INITIAL );
// save links
if( $task = $this->recordManager->getTask( $links, Task::PERSIST, false ) ) {
$task->execute( $pg, $simulate, $ignoreList, self::ACTION_OBJECT );
}
}
}
// references
if( isset( $normality['persist']['references'] ) ) {
foreach( $normality['persist']['references'] as $reference ) {
$references = $repository->referencesGet( $this->object, $reference, Repository::CHANGED );
// save links
if( $references and $task = $this->recordManager->getTask( $references, Task::PERSIST, false ) ) {
$task->execute( $pg, $simulate, $ignoreList, self::ACTION_OBJECT );
}
}
}
return true;
} | [
"protected",
"function",
"additionalSavingTasks",
"(",
"Pg",
"$",
"pg",
",",
"$",
"simulate",
"=",
"false",
",",
"array",
"&",
"$",
"ignoreList",
"=",
"array",
"(",
")",
",",
"$",
"action",
"=",
"self",
"::",
"ACTION_OBJECT",
")",
"{",
"// additional saving tasks?",
"$",
"repository",
"=",
"$",
"this",
"->",
"recordManager",
"->",
"entityManager",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"object",
"->",
"class",
")",
";",
"$",
"normality",
"=",
"$",
"repository",
"->",
"normality",
";",
"// links",
"if",
"(",
"isset",
"(",
"$",
"normality",
"[",
"'persist'",
"]",
"[",
"'links'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"normality",
"[",
"'persist'",
"]",
"[",
"'links'",
"]",
"as",
"$",
"link",
")",
"{",
"$",
"links",
"=",
"$",
"repository",
"->",
"linksGet",
"(",
"$",
"this",
"->",
"object",
",",
"$",
"link",
",",
"Repository",
"::",
"CHANGED",
"+",
"Base",
"::",
"INITIAL",
")",
";",
"// save links",
"if",
"(",
"$",
"task",
"=",
"$",
"this",
"->",
"recordManager",
"->",
"getTask",
"(",
"$",
"links",
",",
"Task",
"::",
"PERSIST",
",",
"false",
")",
")",
"{",
"$",
"task",
"->",
"execute",
"(",
"$",
"pg",
",",
"$",
"simulate",
",",
"$",
"ignoreList",
",",
"self",
"::",
"ACTION_OBJECT",
")",
";",
"}",
"}",
"}",
"// references",
"if",
"(",
"isset",
"(",
"$",
"normality",
"[",
"'persist'",
"]",
"[",
"'references'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"normality",
"[",
"'persist'",
"]",
"[",
"'references'",
"]",
"as",
"$",
"reference",
")",
"{",
"$",
"references",
"=",
"$",
"repository",
"->",
"referencesGet",
"(",
"$",
"this",
"->",
"object",
",",
"$",
"reference",
",",
"Repository",
"::",
"CHANGED",
")",
";",
"// save links",
"if",
"(",
"$",
"references",
"and",
"$",
"task",
"=",
"$",
"this",
"->",
"recordManager",
"->",
"getTask",
"(",
"$",
"references",
",",
"Task",
"::",
"PERSIST",
",",
"false",
")",
")",
"{",
"$",
"task",
"->",
"execute",
"(",
"$",
"pg",
",",
"$",
"simulate",
",",
"$",
"ignoreList",
",",
"self",
"::",
"ACTION_OBJECT",
")",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Execute additional saving tasks.
@return true | [
"Execute",
"additional",
"saving",
"tasks",
"."
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager/Task/NormalityCollection/Persist.php#L240-L277 | train |
jabernardo/lollipop-php | Library/Text/Inflector.php | Inflector.camelize | static function camelize($str) {
// john_aldrich -> john aldrich
$str = str_replace('_', ' ', $str);
// john aldrich -> John Aldrich
$str = ucwords($str);
// John Aldrich -> JohnAldrich
$str = str_replace(' ', '', $str);
return lcfirst($str);
} | php | static function camelize($str) {
// john_aldrich -> john aldrich
$str = str_replace('_', ' ', $str);
// john aldrich -> John Aldrich
$str = ucwords($str);
// John Aldrich -> JohnAldrich
$str = str_replace(' ', '', $str);
return lcfirst($str);
} | [
"static",
"function",
"camelize",
"(",
"$",
"str",
")",
"{",
"// john_aldrich -> john aldrich",
"$",
"str",
"=",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"str",
")",
";",
"// john aldrich -> John Aldrich",
"$",
"str",
"=",
"ucwords",
"(",
"$",
"str",
")",
";",
"// John Aldrich -> JohnAldrich",
"$",
"str",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"str",
")",
";",
"return",
"lcfirst",
"(",
"$",
"str",
")",
";",
"}"
] | Changes word format to camelize
@param string $str String
@return string | [
"Changes",
"word",
"format",
"to",
"camelize"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Text/Inflector.php#L26-L37 | train |
jabernardo/lollipop-php | Library/Text/Inflector.php | Inflector.studly | static function studly($str) {
// john_aldrich -> john aldrich
$str = str_replace('_', ' ', $str);
// john aldrich -> John Aldrich
$str = ucwords($str);
// John Aldrich -> JohnAldrich
$str = str_replace(' ', '', $str);
return $str;
} | php | static function studly($str) {
// john_aldrich -> john aldrich
$str = str_replace('_', ' ', $str);
// john aldrich -> John Aldrich
$str = ucwords($str);
// John Aldrich -> JohnAldrich
$str = str_replace(' ', '', $str);
return $str;
} | [
"static",
"function",
"studly",
"(",
"$",
"str",
")",
"{",
"// john_aldrich -> john aldrich",
"$",
"str",
"=",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"str",
")",
";",
"// john aldrich -> John Aldrich",
"$",
"str",
"=",
"ucwords",
"(",
"$",
"str",
")",
";",
"// John Aldrich -> JohnAldrich",
"$",
"str",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"str",
")",
";",
"return",
"$",
"str",
";",
"}"
] | Changes word format to studly
@param string $str String
@return string | [
"Changes",
"word",
"format",
"to",
"studly"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Text/Inflector.php#L46-L57 | train |
skimia/AngularBundle | Components/FileGenerator/MyJsMin.php | MyJsMin.get | private function get() {
// Get next input character and advance position in file
if ($this->inPos < $this->inLength) {
$c = $this->in[$this->inPos];
++$this->inPos;
}
else {
return self::EOF;
}
// Test for non-problematic characters
if ($c === "\n" || $c === self::EOF || ord($c) >= self::ORD_space) {
return $c;
}
// else
// Make linefeeds into newlines
if ($c === "\r") {
return "\n";
}
// else
// Consider space
return ' ';
} | php | private function get() {
// Get next input character and advance position in file
if ($this->inPos < $this->inLength) {
$c = $this->in[$this->inPos];
++$this->inPos;
}
else {
return self::EOF;
}
// Test for non-problematic characters
if ($c === "\n" || $c === self::EOF || ord($c) >= self::ORD_space) {
return $c;
}
// else
// Make linefeeds into newlines
if ($c === "\r") {
return "\n";
}
// else
// Consider space
return ' ';
} | [
"private",
"function",
"get",
"(",
")",
"{",
"// Get next input character and advance position in file",
"if",
"(",
"$",
"this",
"->",
"inPos",
"<",
"$",
"this",
"->",
"inLength",
")",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"in",
"[",
"$",
"this",
"->",
"inPos",
"]",
";",
"++",
"$",
"this",
"->",
"inPos",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"EOF",
";",
"}",
"// Test for non-problematic characters",
"if",
"(",
"$",
"c",
"===",
"\"\\n\"",
"||",
"$",
"c",
"===",
"self",
"::",
"EOF",
"||",
"ord",
"(",
"$",
"c",
")",
">=",
"self",
"::",
"ORD_space",
")",
"{",
"return",
"$",
"c",
";",
"}",
"// else",
"// Make linefeeds into newlines",
"if",
"(",
"$",
"c",
"===",
"\"\\r\"",
")",
"{",
"return",
"\"\\n\"",
";",
"}",
"// else",
"// Consider space",
"return",
"' '",
";",
"}"
] | Get the next character from the input stream.
If said character is a control character, translate it to a space or linefeed.
@return string The next character from the specified input stream.
@see $in
@see peek() | [
"Get",
"the",
"next",
"character",
"from",
"the",
"input",
"stream",
"."
] | ce12fbc03f8554a7879467e73a739ede8991ec48 | https://github.com/skimia/AngularBundle/blob/ce12fbc03f8554a7879467e73a739ede8991ec48/Components/FileGenerator/MyJsMin.php#L173-L200 | train |
skimia/AngularBundle | Components/FileGenerator/MyJsMin.php | MyJsMin.peek | private function peek()
{
return ($this->inPos < $this->inLength) ? $this->in[$this->inPos] : self::EOF;
} | php | private function peek()
{
return ($this->inPos < $this->inLength) ? $this->in[$this->inPos] : self::EOF;
} | [
"private",
"function",
"peek",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"inPos",
"<",
"$",
"this",
"->",
"inLength",
")",
"?",
"$",
"this",
"->",
"in",
"[",
"$",
"this",
"->",
"inPos",
"]",
":",
"self",
"::",
"EOF",
";",
"}"
] | Get the next character from the input stream, without gettng it.
@return string The next character from the specified input stream, without advancing the position
in the underlying file.
@see $in
@see get() | [
"Get",
"the",
"next",
"character",
"from",
"the",
"input",
"stream",
"without",
"gettng",
"it",
"."
] | ce12fbc03f8554a7879467e73a739ede8991ec48 | https://github.com/skimia/AngularBundle/blob/ce12fbc03f8554a7879467e73a739ede8991ec48/Components/FileGenerator/MyJsMin.php#L221-L224 | train |
skimia/AngularBundle | Components/FileGenerator/MyJsMin.php | MyJsMin.next | function next() {
// Get next char from input, translated if necessary
$c = $this->get();
// Check comment possibility
if ($c == '/') {
// Look ahead : a comment is two slashes or slashes followed by asterisk (to be closed)
switch ($this->peek()) {
case '/' :
// Comment is up to the end of the line
$this->inPos = strpos($this->in, "\n", $this->inPos);
return $this->in[$this->inPos];
case '*' :
// Comment is up to comment close.
// Might not be terminated, if we hit the end of file.
$this->inPos = strpos($this->in, "*/", $this->inPos);
if ( $this->inPos === false ) {
throw new MyJsMinException('UnterminatedComment');
}
$this->inPos += 2;
return ' ';
default :
// Not a comment after all
return $c;
}
}
// No risk of a comment
return $c;
} | php | function next() {
// Get next char from input, translated if necessary
$c = $this->get();
// Check comment possibility
if ($c == '/') {
// Look ahead : a comment is two slashes or slashes followed by asterisk (to be closed)
switch ($this->peek()) {
case '/' :
// Comment is up to the end of the line
$this->inPos = strpos($this->in, "\n", $this->inPos);
return $this->in[$this->inPos];
case '*' :
// Comment is up to comment close.
// Might not be terminated, if we hit the end of file.
$this->inPos = strpos($this->in, "*/", $this->inPos);
if ( $this->inPos === false ) {
throw new MyJsMinException('UnterminatedComment');
}
$this->inPos += 2;
return ' ';
default :
// Not a comment after all
return $c;
}
}
// No risk of a comment
return $c;
} | [
"function",
"next",
"(",
")",
"{",
"// Get next char from input, translated if necessary",
"$",
"c",
"=",
"$",
"this",
"->",
"get",
"(",
")",
";",
"// Check comment possibility",
"if",
"(",
"$",
"c",
"==",
"'/'",
")",
"{",
"// Look ahead : a comment is two slashes or slashes followed by asterisk (to be closed)",
"switch",
"(",
"$",
"this",
"->",
"peek",
"(",
")",
")",
"{",
"case",
"'/'",
":",
"// Comment is up to the end of the line",
"$",
"this",
"->",
"inPos",
"=",
"strpos",
"(",
"$",
"this",
"->",
"in",
",",
"\"\\n\"",
",",
"$",
"this",
"->",
"inPos",
")",
";",
"return",
"$",
"this",
"->",
"in",
"[",
"$",
"this",
"->",
"inPos",
"]",
";",
"case",
"'*'",
":",
"// Comment is up to comment close.",
"// Might not be terminated, if we hit the end of file.",
"$",
"this",
"->",
"inPos",
"=",
"strpos",
"(",
"$",
"this",
"->",
"in",
",",
"\"*/\"",
",",
"$",
"this",
"->",
"inPos",
")",
";",
"if",
"(",
"$",
"this",
"->",
"inPos",
"===",
"false",
")",
"{",
"throw",
"new",
"MyJsMinException",
"(",
"'UnterminatedComment'",
")",
";",
"}",
"$",
"this",
"->",
"inPos",
"+=",
"2",
";",
"return",
"' '",
";",
"default",
":",
"// Not a comment after all",
"return",
"$",
"c",
";",
"}",
"}",
"// No risk of a comment",
"return",
"$",
"c",
";",
"}"
] | Get the next character from the input stream, excluding comments.
{@link peek()} is used to see if a '/' is followed by a '*' or '/'.
Multiline comments are actually returned as a single space.
@return string The next character from the specified input stream, skipping comments.
@see $in | [
"Get",
"the",
"next",
"character",
"from",
"the",
"input",
"stream",
"excluding",
"comments",
"."
] | ce12fbc03f8554a7879467e73a739ede8991ec48 | https://github.com/skimia/AngularBundle/blob/ce12fbc03f8554a7879467e73a739ede8991ec48/Components/FileGenerator/MyJsMin.php#L244-L286 | train |
skimia/AngularBundle | Components/FileGenerator/MyJsMin.php | MyJsMin.action | function action($action) {
// Choice of possible actions
// Note the frequent fallthroughs : the actions are decrementally "long"
switch ($action) {
case self::JSMIN_ACT_FULL :
// Write A to output, then fall through
$this->put($this->theA);
case self::JSMIN_ACT_BUF : // N.B. possible fallthrough from above
// Copy B to A
$tmpA = $this->theA = $this->theB;
// Treating a string as a single char : outputting it whole
// Note that the string-opening char (" or ') is memorized in B
if ($tmpA == '\'' || $tmpA == '"') {
$pos = $this->inPos;
while (true) {
// instead of looping char by char, we directly go to the next
// revelant char, thanks to php strpos function.
$pos = $this->getCloser($this->in, array($this->theB,'\\',"\n"), $pos);
if ( $pos === false ) {
// Whoopsie
throw new MyJsMinException('UnterminatedStringLiteral');
}
$tmpA = $this->in[$pos];
if ($tmpA == $this->theB) {
// String terminated
break; // from while(true)
}
if ($tmpA == "\n") {
// Whoopsie
throw new MyJsMinException('UnterminatedStringLiteral');
}
// else
if ($tmpA == '\\') {
// Escape next char immediately
$pos += 2;
}
}
// cool, we got the whole string
$this->put(substr($this->in, $this->inPos - 1, $pos - $this->inPos + 1));
$this->inPos = $pos + 1;
$this->theA = $tmpA;
}
case self::JSMIN_ACT_IMM : // N.B. possible fallthrough from above
// Get the next B
$this->theB = $this->next();
// Special case of recognising regular expressions (beginning with /) that are
// preceded by '(', ',' or '='
$tmpA = $this->theA;
if ($this->theB == '/' && ($tmpA == '(' || $tmpA == ',' || $tmpA == '=')) {
// Output the two successive chars
$this->put($tmpA);
$this->put($this->theB);
// Look for the end of the RE literal, watching out for escaped chars or a control /
// end of line char (the RE literal then being unterminated !)
$pos = $this->inPos;
while (true) {
// instead of looping char by char, we directly go to the next
// revelant char, thanks to php strpos function.
$pos = $this->getCloser($this->in, array('/','\\',"\n"), $pos);
if ( $pos === false ) {
// Whoopsie
throw new MyJsMinException('UnterminatedRegExpLiteral');
}
$tmpA = $this->in[$pos];
if ($tmpA == '/') {
// RE literal terminated
break; // from while(true)
}
if ( $tmpA == "\n") {
// Whoopsie
throw new MyJsMinException('UnterminatedRegExpLiteral');
}
// else
if ($tmpA == '\\') {
// Escape next char immediately
$pos += 2;
}
}
$this->put(substr($this->in, $this->inPos, $pos - $this->inPos));
$this->inPos = $pos + 1;
$this->theA = $tmpA;
// Move forward after the RE literal
$this->theB = $this->next();
}
break;
default :
throw new MyJsMinException('Expected a JSMin::ACT_* constant in action()');
}
} | php | function action($action) {
// Choice of possible actions
// Note the frequent fallthroughs : the actions are decrementally "long"
switch ($action) {
case self::JSMIN_ACT_FULL :
// Write A to output, then fall through
$this->put($this->theA);
case self::JSMIN_ACT_BUF : // N.B. possible fallthrough from above
// Copy B to A
$tmpA = $this->theA = $this->theB;
// Treating a string as a single char : outputting it whole
// Note that the string-opening char (" or ') is memorized in B
if ($tmpA == '\'' || $tmpA == '"') {
$pos = $this->inPos;
while (true) {
// instead of looping char by char, we directly go to the next
// revelant char, thanks to php strpos function.
$pos = $this->getCloser($this->in, array($this->theB,'\\',"\n"), $pos);
if ( $pos === false ) {
// Whoopsie
throw new MyJsMinException('UnterminatedStringLiteral');
}
$tmpA = $this->in[$pos];
if ($tmpA == $this->theB) {
// String terminated
break; // from while(true)
}
if ($tmpA == "\n") {
// Whoopsie
throw new MyJsMinException('UnterminatedStringLiteral');
}
// else
if ($tmpA == '\\') {
// Escape next char immediately
$pos += 2;
}
}
// cool, we got the whole string
$this->put(substr($this->in, $this->inPos - 1, $pos - $this->inPos + 1));
$this->inPos = $pos + 1;
$this->theA = $tmpA;
}
case self::JSMIN_ACT_IMM : // N.B. possible fallthrough from above
// Get the next B
$this->theB = $this->next();
// Special case of recognising regular expressions (beginning with /) that are
// preceded by '(', ',' or '='
$tmpA = $this->theA;
if ($this->theB == '/' && ($tmpA == '(' || $tmpA == ',' || $tmpA == '=')) {
// Output the two successive chars
$this->put($tmpA);
$this->put($this->theB);
// Look for the end of the RE literal, watching out for escaped chars or a control /
// end of line char (the RE literal then being unterminated !)
$pos = $this->inPos;
while (true) {
// instead of looping char by char, we directly go to the next
// revelant char, thanks to php strpos function.
$pos = $this->getCloser($this->in, array('/','\\',"\n"), $pos);
if ( $pos === false ) {
// Whoopsie
throw new MyJsMinException('UnterminatedRegExpLiteral');
}
$tmpA = $this->in[$pos];
if ($tmpA == '/') {
// RE literal terminated
break; // from while(true)
}
if ( $tmpA == "\n") {
// Whoopsie
throw new MyJsMinException('UnterminatedRegExpLiteral');
}
// else
if ($tmpA == '\\') {
// Escape next char immediately
$pos += 2;
}
}
$this->put(substr($this->in, $this->inPos, $pos - $this->inPos));
$this->inPos = $pos + 1;
$this->theA = $tmpA;
// Move forward after the RE literal
$this->theB = $this->next();
}
break;
default :
throw new MyJsMinException('Expected a JSMin::ACT_* constant in action()');
}
} | [
"function",
"action",
"(",
"$",
"action",
")",
"{",
"// Choice of possible actions",
"// Note the frequent fallthroughs : the actions are decrementally \"long\"",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"self",
"::",
"JSMIN_ACT_FULL",
":",
"// Write A to output, then fall through",
"$",
"this",
"->",
"put",
"(",
"$",
"this",
"->",
"theA",
")",
";",
"case",
"self",
"::",
"JSMIN_ACT_BUF",
":",
"// N.B. possible fallthrough from above",
"// Copy B to A",
"$",
"tmpA",
"=",
"$",
"this",
"->",
"theA",
"=",
"$",
"this",
"->",
"theB",
";",
"// Treating a string as a single char : outputting it whole",
"// Note that the string-opening char (\" or ') is memorized in B",
"if",
"(",
"$",
"tmpA",
"==",
"'\\''",
"||",
"$",
"tmpA",
"==",
"'\"'",
")",
"{",
"$",
"pos",
"=",
"$",
"this",
"->",
"inPos",
";",
"while",
"(",
"true",
")",
"{",
"// instead of looping char by char, we directly go to the next",
"// revelant char, thanks to php strpos function.",
"$",
"pos",
"=",
"$",
"this",
"->",
"getCloser",
"(",
"$",
"this",
"->",
"in",
",",
"array",
"(",
"$",
"this",
"->",
"theB",
",",
"'\\\\'",
",",
"\"\\n\"",
")",
",",
"$",
"pos",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"// Whoopsie",
"throw",
"new",
"MyJsMinException",
"(",
"'UnterminatedStringLiteral'",
")",
";",
"}",
"$",
"tmpA",
"=",
"$",
"this",
"->",
"in",
"[",
"$",
"pos",
"]",
";",
"if",
"(",
"$",
"tmpA",
"==",
"$",
"this",
"->",
"theB",
")",
"{",
"// String terminated",
"break",
";",
"// from while(true)",
"}",
"if",
"(",
"$",
"tmpA",
"==",
"\"\\n\"",
")",
"{",
"// Whoopsie",
"throw",
"new",
"MyJsMinException",
"(",
"'UnterminatedStringLiteral'",
")",
";",
"}",
"// else",
"if",
"(",
"$",
"tmpA",
"==",
"'\\\\'",
")",
"{",
"// Escape next char immediately",
"$",
"pos",
"+=",
"2",
";",
"}",
"}",
"// cool, we got the whole string",
"$",
"this",
"->",
"put",
"(",
"substr",
"(",
"$",
"this",
"->",
"in",
",",
"$",
"this",
"->",
"inPos",
"-",
"1",
",",
"$",
"pos",
"-",
"$",
"this",
"->",
"inPos",
"+",
"1",
")",
")",
";",
"$",
"this",
"->",
"inPos",
"=",
"$",
"pos",
"+",
"1",
";",
"$",
"this",
"->",
"theA",
"=",
"$",
"tmpA",
";",
"}",
"case",
"self",
"::",
"JSMIN_ACT_IMM",
":",
"// N.B. possible fallthrough from above",
"// Get the next B",
"$",
"this",
"->",
"theB",
"=",
"$",
"this",
"->",
"next",
"(",
")",
";",
"// Special case of recognising regular expressions (beginning with /) that are",
"// preceded by '(', ',' or '='",
"$",
"tmpA",
"=",
"$",
"this",
"->",
"theA",
";",
"if",
"(",
"$",
"this",
"->",
"theB",
"==",
"'/'",
"&&",
"(",
"$",
"tmpA",
"==",
"'('",
"||",
"$",
"tmpA",
"==",
"','",
"||",
"$",
"tmpA",
"==",
"'='",
")",
")",
"{",
"// Output the two successive chars",
"$",
"this",
"->",
"put",
"(",
"$",
"tmpA",
")",
";",
"$",
"this",
"->",
"put",
"(",
"$",
"this",
"->",
"theB",
")",
";",
"// Look for the end of the RE literal, watching out for escaped chars or a control /",
"// end of line char (the RE literal then being unterminated !)",
"$",
"pos",
"=",
"$",
"this",
"->",
"inPos",
";",
"while",
"(",
"true",
")",
"{",
"// instead of looping char by char, we directly go to the next",
"// revelant char, thanks to php strpos function.",
"$",
"pos",
"=",
"$",
"this",
"->",
"getCloser",
"(",
"$",
"this",
"->",
"in",
",",
"array",
"(",
"'/'",
",",
"'\\\\'",
",",
"\"\\n\"",
")",
",",
"$",
"pos",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"// Whoopsie",
"throw",
"new",
"MyJsMinException",
"(",
"'UnterminatedRegExpLiteral'",
")",
";",
"}",
"$",
"tmpA",
"=",
"$",
"this",
"->",
"in",
"[",
"$",
"pos",
"]",
";",
"if",
"(",
"$",
"tmpA",
"==",
"'/'",
")",
"{",
"// RE literal terminated",
"break",
";",
"// from while(true)",
"}",
"if",
"(",
"$",
"tmpA",
"==",
"\"\\n\"",
")",
"{",
"// Whoopsie",
"throw",
"new",
"MyJsMinException",
"(",
"'UnterminatedRegExpLiteral'",
")",
";",
"}",
"// else",
"if",
"(",
"$",
"tmpA",
"==",
"'\\\\'",
")",
"{",
"// Escape next char immediately",
"$",
"pos",
"+=",
"2",
";",
"}",
"}",
"$",
"this",
"->",
"put",
"(",
"substr",
"(",
"$",
"this",
"->",
"in",
",",
"$",
"this",
"->",
"inPos",
",",
"$",
"pos",
"-",
"$",
"this",
"->",
"inPos",
")",
")",
";",
"$",
"this",
"->",
"inPos",
"=",
"$",
"pos",
"+",
"1",
";",
"$",
"this",
"->",
"theA",
"=",
"$",
"tmpA",
";",
"// Move forward after the RE literal",
"$",
"this",
"->",
"theB",
"=",
"$",
"this",
"->",
"next",
"(",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"MyJsMinException",
"(",
"'Expected a JSMin::ACT_* constant in action()'",
")",
";",
"}",
"}"
] | Do something !
The action to perform is determined by the argument :
JSMin::ACT_FULL : Output A. Copy B to A. Get the next B.
JSMin::ACT_BUF : Copy B to A. Get the next B. (Delete A).
JSMin::ACT_IMM : Get the next B. (Delete B).
A string is treated as a single character. Also, regular expressions are recognized if preceded
by '(', ',' or '='.
@param int $action The action to perform : one of the JSMin::ACT_* constants. | [
"Do",
"something",
"!"
] | ce12fbc03f8554a7879467e73a739ede8991ec48 | https://github.com/skimia/AngularBundle/blob/ce12fbc03f8554a7879467e73a739ede8991ec48/Components/FileGenerator/MyJsMin.php#L302-L415 | train |
eliasis-framework/complement | src/Traits/ComplementHandler.php | ComplementHandler.getControllerInstance | public function getControllerInstance($class, $namespace = '')
{
if (isset($this->complement['namespaces'])) {
if (isset($this->complement['namespaces'][$namespace])) {
$namespace = $this->complement['namespaces'][$namespace];
$_class = $namespace . $class;
if (class_exists($_class)) {
return call_user_func([$_class, 'getInstance']);
}
return false;
}
foreach ($this->complement['namespaces'] as $key => $namespace) {
$instance = $namespace . $class;
if (class_exists($instance)) {
return call_user_func([$instance, 'getInstance']);
}
}
}
return false;
} | php | public function getControllerInstance($class, $namespace = '')
{
if (isset($this->complement['namespaces'])) {
if (isset($this->complement['namespaces'][$namespace])) {
$namespace = $this->complement['namespaces'][$namespace];
$_class = $namespace . $class;
if (class_exists($_class)) {
return call_user_func([$_class, 'getInstance']);
}
return false;
}
foreach ($this->complement['namespaces'] as $key => $namespace) {
$instance = $namespace . $class;
if (class_exists($instance)) {
return call_user_func([$instance, 'getInstance']);
}
}
}
return false;
} | [
"public",
"function",
"getControllerInstance",
"(",
"$",
"class",
",",
"$",
"namespace",
"=",
"''",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"complement",
"[",
"'namespaces'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"complement",
"[",
"'namespaces'",
"]",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"namespace",
"=",
"$",
"this",
"->",
"complement",
"[",
"'namespaces'",
"]",
"[",
"$",
"namespace",
"]",
";",
"$",
"_class",
"=",
"$",
"namespace",
".",
"$",
"class",
";",
"if",
"(",
"class_exists",
"(",
"$",
"_class",
")",
")",
"{",
"return",
"call_user_func",
"(",
"[",
"$",
"_class",
",",
"'getInstance'",
"]",
")",
";",
"}",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"complement",
"[",
"'namespaces'",
"]",
"as",
"$",
"key",
"=>",
"$",
"namespace",
")",
"{",
"$",
"instance",
"=",
"$",
"namespace",
".",
"$",
"class",
";",
"if",
"(",
"class_exists",
"(",
"$",
"instance",
")",
")",
"{",
"return",
"call_user_func",
"(",
"[",
"$",
"instance",
",",
"'getInstance'",
"]",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Get complement controller instance.
@since 1.1.0
@param array $class → class name
@param array $namespace → namespace index
@return object|false → class instance or false | [
"Get",
"complement",
"controller",
"instance",
"."
] | d50e92cf01600ff4573bf1761c312069044748c3 | https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementHandler.php#L102-L126 | train |
eliasis-framework/complement | src/Traits/ComplementHandler.php | ComplementHandler.setComplement | private function setComplement($complement)
{
$this->getStates();
$this->setComplementParams($complement);
$state = $this->getState();
$action = $this->getAction($state);
$this->setAction($action);
$this->setState($state);
$this->getSettings();
$states = ['active', 'outdated'];
if (in_array($action, self::$hooks, true) || in_array($state, $states, true)) {
$this->addRoutes();
$this->addActions();
$this->doActions($action);
}
return true;
} | php | private function setComplement($complement)
{
$this->getStates();
$this->setComplementParams($complement);
$state = $this->getState();
$action = $this->getAction($state);
$this->setAction($action);
$this->setState($state);
$this->getSettings();
$states = ['active', 'outdated'];
if (in_array($action, self::$hooks, true) || in_array($state, $states, true)) {
$this->addRoutes();
$this->addActions();
$this->doActions($action);
}
return true;
} | [
"private",
"function",
"setComplement",
"(",
"$",
"complement",
")",
"{",
"$",
"this",
"->",
"getStates",
"(",
")",
";",
"$",
"this",
"->",
"setComplementParams",
"(",
"$",
"complement",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"action",
"=",
"$",
"this",
"->",
"getAction",
"(",
"$",
"state",
")",
";",
"$",
"this",
"->",
"setAction",
"(",
"$",
"action",
")",
";",
"$",
"this",
"->",
"setState",
"(",
"$",
"state",
")",
";",
"$",
"this",
"->",
"getSettings",
"(",
")",
";",
"$",
"states",
"=",
"[",
"'active'",
",",
"'outdated'",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"action",
",",
"self",
"::",
"$",
"hooks",
",",
"true",
")",
"||",
"in_array",
"(",
"$",
"state",
",",
"$",
"states",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"addRoutes",
"(",
")",
";",
"$",
"this",
"->",
"addActions",
"(",
")",
";",
"$",
"this",
"->",
"doActions",
"(",
"$",
"action",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Set complement.
@param string $complement → complement settings
@uses \Eliasis\Complement\Traits\ComplementState->getStates()
@uses \Eliasis\Complement\Traits\ComplementState->getState()
@uses \Eliasis\Complement\Traits\ComplementState->setState()
@uses \Eliasis\Complement\Traits\ComplementAction->getAction()
@uses \Eliasis\Complement\Traits\ComplementAction->setAction()
@uses \Eliasis\Complement\Traits\ComplementAction->addActions()
@uses \Eliasis\Complement\Traits\ComplementAction->doActions()
@return bool true | [
"Set",
"complement",
"."
] | d50e92cf01600ff4573bf1761c312069044748c3 | https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementHandler.php#L143-L164 | train |
eliasis-framework/complement | src/Traits/ComplementHandler.php | ComplementHandler.setComplementParams | private function setComplementParams($complement)
{
$params = array_intersect_key(
array_flip(self::$required),
$complement
);
$slug = explode('.', basename($complement['config-file']));
$default['slug'] = $slug[0];
$complementType = self::getType('strtoupper');
$path = App::$complementType() . $default['slug'] . '/';
if (count($params) != 7) {
$msg = self::getType('ucfirst') . " configuration file isn't correct";
throw new ComplementException($msg . ': ' . $path . '.');
}
$default['url-import'] = '';
$default['hooks-controller'] = 'Launcher';
$default['path']['root'] = Url::addBackSlash($path);
$default['folder'] = $default['slug'] . '/';
$default['license'] = 'MIT';
$default['author'] = '';
$default['author-url'] = '';
$default['extra'] = [];
$lang = $this->getLanguage();
if (isset($complement['name'][$lang])) {
$complement['name'] = $complement['name'][$lang];
}
if (isset($complement['description'][$lang])) {
$complement['description'] = $complement['description'][$lang];
}
$this->complement = array_merge($default, $complement);
$this->setImage();
} | php | private function setComplementParams($complement)
{
$params = array_intersect_key(
array_flip(self::$required),
$complement
);
$slug = explode('.', basename($complement['config-file']));
$default['slug'] = $slug[0];
$complementType = self::getType('strtoupper');
$path = App::$complementType() . $default['slug'] . '/';
if (count($params) != 7) {
$msg = self::getType('ucfirst') . " configuration file isn't correct";
throw new ComplementException($msg . ': ' . $path . '.');
}
$default['url-import'] = '';
$default['hooks-controller'] = 'Launcher';
$default['path']['root'] = Url::addBackSlash($path);
$default['folder'] = $default['slug'] . '/';
$default['license'] = 'MIT';
$default['author'] = '';
$default['author-url'] = '';
$default['extra'] = [];
$lang = $this->getLanguage();
if (isset($complement['name'][$lang])) {
$complement['name'] = $complement['name'][$lang];
}
if (isset($complement['description'][$lang])) {
$complement['description'] = $complement['description'][$lang];
}
$this->complement = array_merge($default, $complement);
$this->setImage();
} | [
"private",
"function",
"setComplementParams",
"(",
"$",
"complement",
")",
"{",
"$",
"params",
"=",
"array_intersect_key",
"(",
"array_flip",
"(",
"self",
"::",
"$",
"required",
")",
",",
"$",
"complement",
")",
";",
"$",
"slug",
"=",
"explode",
"(",
"'.'",
",",
"basename",
"(",
"$",
"complement",
"[",
"'config-file'",
"]",
")",
")",
";",
"$",
"default",
"[",
"'slug'",
"]",
"=",
"$",
"slug",
"[",
"0",
"]",
";",
"$",
"complementType",
"=",
"self",
"::",
"getType",
"(",
"'strtoupper'",
")",
";",
"$",
"path",
"=",
"App",
"::",
"$",
"complementType",
"(",
")",
".",
"$",
"default",
"[",
"'slug'",
"]",
".",
"'/'",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
"!=",
"7",
")",
"{",
"$",
"msg",
"=",
"self",
"::",
"getType",
"(",
"'ucfirst'",
")",
".",
"\" configuration file isn't correct\"",
";",
"throw",
"new",
"ComplementException",
"(",
"$",
"msg",
".",
"': '",
".",
"$",
"path",
".",
"'.'",
")",
";",
"}",
"$",
"default",
"[",
"'url-import'",
"]",
"=",
"''",
";",
"$",
"default",
"[",
"'hooks-controller'",
"]",
"=",
"'Launcher'",
";",
"$",
"default",
"[",
"'path'",
"]",
"[",
"'root'",
"]",
"=",
"Url",
"::",
"addBackSlash",
"(",
"$",
"path",
")",
";",
"$",
"default",
"[",
"'folder'",
"]",
"=",
"$",
"default",
"[",
"'slug'",
"]",
".",
"'/'",
";",
"$",
"default",
"[",
"'license'",
"]",
"=",
"'MIT'",
";",
"$",
"default",
"[",
"'author'",
"]",
"=",
"''",
";",
"$",
"default",
"[",
"'author-url'",
"]",
"=",
"''",
";",
"$",
"default",
"[",
"'extra'",
"]",
"=",
"[",
"]",
";",
"$",
"lang",
"=",
"$",
"this",
"->",
"getLanguage",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"complement",
"[",
"'name'",
"]",
"[",
"$",
"lang",
"]",
")",
")",
"{",
"$",
"complement",
"[",
"'name'",
"]",
"=",
"$",
"complement",
"[",
"'name'",
"]",
"[",
"$",
"lang",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"complement",
"[",
"'description'",
"]",
"[",
"$",
"lang",
"]",
")",
")",
"{",
"$",
"complement",
"[",
"'description'",
"]",
"=",
"$",
"complement",
"[",
"'description'",
"]",
"[",
"$",
"lang",
"]",
";",
"}",
"$",
"this",
"->",
"complement",
"=",
"array_merge",
"(",
"$",
"default",
",",
"$",
"complement",
")",
";",
"$",
"this",
"->",
"setImage",
"(",
")",
";",
"}"
] | Check required params and set complement params.
@param string $complement → complement settings
@uses \Eliasis\Complement\Complement->$complement
@uses \Eliasis\Complement\Traits\ComplementHandler::getType()
@uses \Eliasis\Complement\Traits\ComplementAction->$hooks
@throws ComplementException → complement configuration file error | [
"Check",
"required",
"params",
"and",
"set",
"complement",
"params",
"."
] | d50e92cf01600ff4573bf1761c312069044748c3 | https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementHandler.php#L177-L216 | train |
eliasis-framework/complement | src/Traits/ComplementHandler.php | ComplementHandler.getLanguage | private function getLanguage()
{
$wpLang = (function_exists('get_locale')) ? get_locale() : null;
$browserLang = null;
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$browserLang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
return substr($wpLang ?: $browserLang ?: 'en', 0, 2);
} | php | private function getLanguage()
{
$wpLang = (function_exists('get_locale')) ? get_locale() : null;
$browserLang = null;
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$browserLang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
return substr($wpLang ?: $browserLang ?: 'en', 0, 2);
} | [
"private",
"function",
"getLanguage",
"(",
")",
"{",
"$",
"wpLang",
"=",
"(",
"function_exists",
"(",
"'get_locale'",
")",
")",
"?",
"get_locale",
"(",
")",
":",
"null",
";",
"$",
"browserLang",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
")",
"{",
"$",
"browserLang",
"=",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
";",
"}",
"return",
"substr",
"(",
"$",
"wpLang",
"?",
":",
"$",
"browserLang",
"?",
":",
"'en'",
",",
"0",
",",
"2",
")",
";",
"}"
] | Gets the current locale.
@uses \get_locale() → gets the current locale in WordPress | [
"Gets",
"the",
"current",
"locale",
"."
] | d50e92cf01600ff4573bf1761c312069044748c3 | https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementHandler.php#L247-L256 | train |
eliasis-framework/complement | src/Traits/ComplementHandler.php | ComplementHandler.setImage | private function setImage()
{
$slug = $this->complement['slug'];
$complementType = self::getType('strtoupper');
$complementPath = App::$complementType();
$complementUrl = $complementType . '_URL';
$complementUrl = App::$complementUrl();
$file = 'public/images/' . $slug . '.png';
$filepath = $complementPath . $slug . '/' . $file;
$url = 'https://raw.githubusercontent.com/Eliasis-Framework/Complement/';
$directory = $complementUrl . $slug . '/' . $file;
$repository = rtrim($this->complement['url-import'], '/') . "/$file";
$default = $url . 'master/src/static/images/default.png';
if (File::exists($filepath)) {
$this->complement['image'] = $directory;
} elseif (File::exists($repository)) {
$this->complement['image'] = $repository;
} else {
$this->complement['image'] = $default;
}
} | php | private function setImage()
{
$slug = $this->complement['slug'];
$complementType = self::getType('strtoupper');
$complementPath = App::$complementType();
$complementUrl = $complementType . '_URL';
$complementUrl = App::$complementUrl();
$file = 'public/images/' . $slug . '.png';
$filepath = $complementPath . $slug . '/' . $file;
$url = 'https://raw.githubusercontent.com/Eliasis-Framework/Complement/';
$directory = $complementUrl . $slug . '/' . $file;
$repository = rtrim($this->complement['url-import'], '/') . "/$file";
$default = $url . 'master/src/static/images/default.png';
if (File::exists($filepath)) {
$this->complement['image'] = $directory;
} elseif (File::exists($repository)) {
$this->complement['image'] = $repository;
} else {
$this->complement['image'] = $default;
}
} | [
"private",
"function",
"setImage",
"(",
")",
"{",
"$",
"slug",
"=",
"$",
"this",
"->",
"complement",
"[",
"'slug'",
"]",
";",
"$",
"complementType",
"=",
"self",
"::",
"getType",
"(",
"'strtoupper'",
")",
";",
"$",
"complementPath",
"=",
"App",
"::",
"$",
"complementType",
"(",
")",
";",
"$",
"complementUrl",
"=",
"$",
"complementType",
".",
"'_URL'",
";",
"$",
"complementUrl",
"=",
"App",
"::",
"$",
"complementUrl",
"(",
")",
";",
"$",
"file",
"=",
"'public/images/'",
".",
"$",
"slug",
".",
"'.png'",
";",
"$",
"filepath",
"=",
"$",
"complementPath",
".",
"$",
"slug",
".",
"'/'",
".",
"$",
"file",
";",
"$",
"url",
"=",
"'https://raw.githubusercontent.com/Eliasis-Framework/Complement/'",
";",
"$",
"directory",
"=",
"$",
"complementUrl",
".",
"$",
"slug",
".",
"'/'",
".",
"$",
"file",
";",
"$",
"repository",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"complement",
"[",
"'url-import'",
"]",
",",
"'/'",
")",
".",
"\"/$file\"",
";",
"$",
"default",
"=",
"$",
"url",
".",
"'master/src/static/images/default.png'",
";",
"if",
"(",
"File",
"::",
"exists",
"(",
"$",
"filepath",
")",
")",
"{",
"$",
"this",
"->",
"complement",
"[",
"'image'",
"]",
"=",
"$",
"directory",
";",
"}",
"elseif",
"(",
"File",
"::",
"exists",
"(",
"$",
"repository",
")",
")",
"{",
"$",
"this",
"->",
"complement",
"[",
"'image'",
"]",
"=",
"$",
"repository",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"complement",
"[",
"'image'",
"]",
"=",
"$",
"default",
";",
"}",
"}"
] | Set image url.
@uses \Eliasis\Framework\App::COMPLEMENT()
@uses \Eliasis\Framework\App::COMPLEMENT_URL()
@uses \Eliasis\Complement\Complement->$complement
@uses \Eliasis\Complement\Traits\ComplementHandler::getType() | [
"Set",
"image",
"url",
"."
] | d50e92cf01600ff4573bf1761c312069044748c3 | https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementHandler.php#L266-L293 | train |
eliasis-framework/complement | src/Traits/ComplementHandler.php | ComplementHandler.getType | private static function getType($mode = 'strtolower', $plural = true)
{
$namespace = get_called_class();
$class = explode('\\', $namespace);
$complement = strtolower(array_pop($class) . ($plural ? 's' : ''));
switch ($mode) {
case 'ucfirst':
return ucfirst($complement);
case 'strtoupper':
return strtoupper($complement);
default:
return $complement;
}
} | php | private static function getType($mode = 'strtolower', $plural = true)
{
$namespace = get_called_class();
$class = explode('\\', $namespace);
$complement = strtolower(array_pop($class) . ($plural ? 's' : ''));
switch ($mode) {
case 'ucfirst':
return ucfirst($complement);
case 'strtoupper':
return strtoupper($complement);
default:
return $complement;
}
} | [
"private",
"static",
"function",
"getType",
"(",
"$",
"mode",
"=",
"'strtolower'",
",",
"$",
"plural",
"=",
"true",
")",
"{",
"$",
"namespace",
"=",
"get_called_class",
"(",
")",
";",
"$",
"class",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"namespace",
")",
";",
"$",
"complement",
"=",
"strtolower",
"(",
"array_pop",
"(",
"$",
"class",
")",
".",
"(",
"$",
"plural",
"?",
"'s'",
":",
"''",
")",
")",
";",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"'ucfirst'",
":",
"return",
"ucfirst",
"(",
"$",
"complement",
")",
";",
"case",
"'strtoupper'",
":",
"return",
"strtoupper",
"(",
"$",
"complement",
")",
";",
"default",
":",
"return",
"$",
"complement",
";",
"}",
"}"
] | Get complement type.
@param string $mode → ucfirst|strtoupper|strtolower
@param bool $plural → plural|singular
@return object → complement instance | [
"Get",
"complement",
"type",
"."
] | d50e92cf01600ff4573bf1761c312069044748c3 | https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementHandler.php#L303-L317 | train |
eliasis-framework/complement | src/Traits/ComplementHandler.php | ComplementHandler.addRoutes | private function addRoutes()
{
if (class_exists($Router = 'Josantonius\Router\Router')) {
if (isset($this->complement['routes'])) {
$Router::add($this->complement['routes']);
}
}
} | php | private function addRoutes()
{
if (class_exists($Router = 'Josantonius\Router\Router')) {
if (isset($this->complement['routes'])) {
$Router::add($this->complement['routes']);
}
}
} | [
"private",
"function",
"addRoutes",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"Router",
"=",
"'Josantonius\\Router\\Router'",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"complement",
"[",
"'routes'",
"]",
")",
")",
"{",
"$",
"Router",
"::",
"add",
"(",
"$",
"this",
"->",
"complement",
"[",
"'routes'",
"]",
")",
";",
"}",
"}",
"}"
] | Add complement routes if exists.
@uses \Josantonius\Router\Router::add
@uses \Eliasis\Complement\Complement->$complement | [
"Add",
"complement",
"routes",
"if",
"exists",
"."
] | d50e92cf01600ff4573bf1761c312069044748c3 | https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementHandler.php#L325-L332 | train |
Fulfillment-dot-com/api-wrapper-php | src/Api.php | Api.refreshAccessToken | public function refreshAccessToken()
{
$newToken = $this->http->requestAccessToken();
if (!is_null($newToken))
{
$this->config->setAccessToken($newToken);
$this->http = new Request($this->guzzle, $this->config, $this->climate);
if ($this->config->shouldStoreToken())
{
file_put_contents(Helper::getStoragePath($this->config->getStorageTokenFilename()), $newToken);
}
}
return $newToken;
} | php | public function refreshAccessToken()
{
$newToken = $this->http->requestAccessToken();
if (!is_null($newToken))
{
$this->config->setAccessToken($newToken);
$this->http = new Request($this->guzzle, $this->config, $this->climate);
if ($this->config->shouldStoreToken())
{
file_put_contents(Helper::getStoragePath($this->config->getStorageTokenFilename()), $newToken);
}
}
return $newToken;
} | [
"public",
"function",
"refreshAccessToken",
"(",
")",
"{",
"$",
"newToken",
"=",
"$",
"this",
"->",
"http",
"->",
"requestAccessToken",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"newToken",
")",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"setAccessToken",
"(",
"$",
"newToken",
")",
";",
"$",
"this",
"->",
"http",
"=",
"new",
"Request",
"(",
"$",
"this",
"->",
"guzzle",
",",
"$",
"this",
"->",
"config",
",",
"$",
"this",
"->",
"climate",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"shouldStoreToken",
"(",
")",
")",
"{",
"file_put_contents",
"(",
"Helper",
"::",
"getStoragePath",
"(",
"$",
"this",
"->",
"config",
"->",
"getStorageTokenFilename",
"(",
")",
")",
",",
"$",
"newToken",
")",
";",
"}",
"}",
"return",
"$",
"newToken",
";",
"}"
] | Get a new access token
@return string|null
@throws Exceptions\MissingCredentialException
@throws Exceptions\UnauthorizedMerchantException | [
"Get",
"a",
"new",
"access",
"token"
] | f4352843d060bc1b460c1283f25c210c9b94d324 | https://github.com/Fulfillment-dot-com/api-wrapper-php/blob/f4352843d060bc1b460c1283f25c210c9b94d324/src/Api.php#L208-L222 | train |
modulusphp/utility | Command.php | Command.wait | public static function wait(string $args) : ?SymfonyProcess
{
$process = new SymfonyProcess('php ' . Accessor::$appRoot . 'craftsman ' . $args);
$process->start();
$process->wait();
$process->stop();
return $process;
} | php | public static function wait(string $args) : ?SymfonyProcess
{
$process = new SymfonyProcess('php ' . Accessor::$appRoot . 'craftsman ' . $args);
$process->start();
$process->wait();
$process->stop();
return $process;
} | [
"public",
"static",
"function",
"wait",
"(",
"string",
"$",
"args",
")",
":",
"?",
"SymfonyProcess",
"{",
"$",
"process",
"=",
"new",
"SymfonyProcess",
"(",
"'php '",
".",
"Accessor",
"::",
"$",
"appRoot",
".",
"'craftsman '",
".",
"$",
"args",
")",
";",
"$",
"process",
"->",
"start",
"(",
")",
";",
"$",
"process",
"->",
"wait",
"(",
")",
";",
"$",
"process",
"->",
"stop",
"(",
")",
";",
"return",
"$",
"process",
";",
"}"
] | Run and wait
@param string $args
@return SymfonyProcess $process | [
"Run",
"and",
"wait"
] | c1e127539b13d3ec8381e41c64b881e0701807f5 | https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/Command.php#L47-L56 | train |
brunschgi/TerrificComposerBundle | Service/ModuleManager.php | ModuleManager.createModule | public function createModule(Module $module)
{
$dst = $this->rootDir.'/../src/Terrific/Module/'.StringUtils::camelize($module->getName());
if($this->toolbarMode === ToolbarListener::DEMO) {
// prevent module creation in demo mode
throw new \Exception('This action is not supported in demo mode');
} else {
if($this->moduleTemplate) {
$this->copy($this->moduleTemplate, $dst, $module);
}
$this->copy($this->defaultTemplate, $dst, $module);
}
} | php | public function createModule(Module $module)
{
$dst = $this->rootDir.'/../src/Terrific/Module/'.StringUtils::camelize($module->getName());
if($this->toolbarMode === ToolbarListener::DEMO) {
// prevent module creation in demo mode
throw new \Exception('This action is not supported in demo mode');
} else {
if($this->moduleTemplate) {
$this->copy($this->moduleTemplate, $dst, $module);
}
$this->copy($this->defaultTemplate, $dst, $module);
}
} | [
"public",
"function",
"createModule",
"(",
"Module",
"$",
"module",
")",
"{",
"$",
"dst",
"=",
"$",
"this",
"->",
"rootDir",
".",
"'/../src/Terrific/Module/'",
".",
"StringUtils",
"::",
"camelize",
"(",
"$",
"module",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"toolbarMode",
"===",
"ToolbarListener",
"::",
"DEMO",
")",
"{",
"// prevent module creation in demo mode",
"throw",
"new",
"\\",
"Exception",
"(",
"'This action is not supported in demo mode'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"moduleTemplate",
")",
"{",
"$",
"this",
"->",
"copy",
"(",
"$",
"this",
"->",
"moduleTemplate",
",",
"$",
"dst",
",",
"$",
"module",
")",
";",
"}",
"$",
"this",
"->",
"copy",
"(",
"$",
"this",
"->",
"defaultTemplate",
",",
"$",
"dst",
",",
"$",
"module",
")",
";",
"}",
"}"
] | Creates a Terrific Module
@param Module $module The module to create | [
"Creates",
"a",
"Terrific",
"Module"
] | 6eef4ace887c19ef166ab6654de385bc1ffbf5f1 | https://github.com/brunschgi/TerrificComposerBundle/blob/6eef4ace887c19ef166ab6654de385bc1ffbf5f1/Service/ModuleManager.php#L61-L75 | train |
brunschgi/TerrificComposerBundle | Service/ModuleManager.php | ModuleManager.createSkin | public function createSkin(Skin $skin)
{
$module = new Module();
$module->setName($skin->getModule());
$module->addSkin($skin);
$dst = $this->rootDir.'/../src/Terrific/Module/'.StringUtils::camelize($module->getName());
if($this->toolbarMode === ToolbarListener::DEMO) {
// prevent module creation in demo mode
throw new \Exception('This action is not supported in demo mode');
} else {
if($this->moduleTemplate) {
$this->copy($this->moduleTemplate, $dst, $module);
}
$this->copy($this->defaultTemplate, $dst, $module);
}
} | php | public function createSkin(Skin $skin)
{
$module = new Module();
$module->setName($skin->getModule());
$module->addSkin($skin);
$dst = $this->rootDir.'/../src/Terrific/Module/'.StringUtils::camelize($module->getName());
if($this->toolbarMode === ToolbarListener::DEMO) {
// prevent module creation in demo mode
throw new \Exception('This action is not supported in demo mode');
} else {
if($this->moduleTemplate) {
$this->copy($this->moduleTemplate, $dst, $module);
}
$this->copy($this->defaultTemplate, $dst, $module);
}
} | [
"public",
"function",
"createSkin",
"(",
"Skin",
"$",
"skin",
")",
"{",
"$",
"module",
"=",
"new",
"Module",
"(",
")",
";",
"$",
"module",
"->",
"setName",
"(",
"$",
"skin",
"->",
"getModule",
"(",
")",
")",
";",
"$",
"module",
"->",
"addSkin",
"(",
"$",
"skin",
")",
";",
"$",
"dst",
"=",
"$",
"this",
"->",
"rootDir",
".",
"'/../src/Terrific/Module/'",
".",
"StringUtils",
"::",
"camelize",
"(",
"$",
"module",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"toolbarMode",
"===",
"ToolbarListener",
"::",
"DEMO",
")",
"{",
"// prevent module creation in demo mode",
"throw",
"new",
"\\",
"Exception",
"(",
"'This action is not supported in demo mode'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"moduleTemplate",
")",
"{",
"$",
"this",
"->",
"copy",
"(",
"$",
"this",
"->",
"moduleTemplate",
",",
"$",
"dst",
",",
"$",
"module",
")",
";",
"}",
"$",
"this",
"->",
"copy",
"(",
"$",
"this",
"->",
"defaultTemplate",
",",
"$",
"dst",
",",
"$",
"module",
")",
";",
"}",
"}"
] | Creates a Terrific Skin
@param Skin $skin The skin to create | [
"Creates",
"a",
"Terrific",
"Skin"
] | 6eef4ace887c19ef166ab6654de385bc1ffbf5f1 | https://github.com/brunschgi/TerrificComposerBundle/blob/6eef4ace887c19ef166ab6654de385bc1ffbf5f1/Service/ModuleManager.php#L82-L100 | train |
brunschgi/TerrificComposerBundle | Service/ModuleManager.php | ModuleManager.getModules | public function getModules()
{
$modules = array();
$dir = $this->rootDir.'/../src/Terrific/Module/';
$finder = new Finder();
$finder->directories()->in($dir)->depth('== 0');
foreach ($finder as $file) {
$module = $file->getFilename();
$modules[$module] = $this->getModuleByName($module, 'small');
}
sort($modules);
return $modules;
} | php | public function getModules()
{
$modules = array();
$dir = $this->rootDir.'/../src/Terrific/Module/';
$finder = new Finder();
$finder->directories()->in($dir)->depth('== 0');
foreach ($finder as $file) {
$module = $file->getFilename();
$modules[$module] = $this->getModuleByName($module, 'small');
}
sort($modules);
return $modules;
} | [
"public",
"function",
"getModules",
"(",
")",
"{",
"$",
"modules",
"=",
"array",
"(",
")",
";",
"$",
"dir",
"=",
"$",
"this",
"->",
"rootDir",
".",
"'/../src/Terrific/Module/'",
";",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"directories",
"(",
")",
"->",
"in",
"(",
"$",
"dir",
")",
"->",
"depth",
"(",
"'== 0'",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"module",
"=",
"$",
"file",
"->",
"getFilename",
"(",
")",
";",
"$",
"modules",
"[",
"$",
"module",
"]",
"=",
"$",
"this",
"->",
"getModuleByName",
"(",
"$",
"module",
",",
"'small'",
")",
";",
"}",
"sort",
"(",
"$",
"modules",
")",
";",
"return",
"$",
"modules",
";",
"}"
] | Gets all existing Modules
@return array All existing Module instances | [
"Gets",
"all",
"existing",
"Modules"
] | 6eef4ace887c19ef166ab6654de385bc1ffbf5f1 | https://github.com/brunschgi/TerrificComposerBundle/blob/6eef4ace887c19ef166ab6654de385bc1ffbf5f1/Service/ModuleManager.php#L107-L124 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.getCount | public function getCount($where = '', $variables = null)
{
$where = $this->formatWhereClause($where);
$response = $this->driver->query("select count(*) as numberOfItems from " . $this->getTable() . ' ' . $where . ";", $variables);
if (!$response->count()) return 0;
$response = $response->row();
return intval($response->numberOfItems);
} | php | public function getCount($where = '', $variables = null)
{
$where = $this->formatWhereClause($where);
$response = $this->driver->query("select count(*) as numberOfItems from " . $this->getTable() . ' ' . $where . ";", $variables);
if (!$response->count()) return 0;
$response = $response->row();
return intval($response->numberOfItems);
} | [
"public",
"function",
"getCount",
"(",
"$",
"where",
"=",
"''",
",",
"$",
"variables",
"=",
"null",
")",
"{",
"$",
"where",
"=",
"$",
"this",
"->",
"formatWhereClause",
"(",
"$",
"where",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"query",
"(",
"\"select count(*) as numberOfItems from \"",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"' '",
".",
"$",
"where",
".",
"\";\"",
",",
"$",
"variables",
")",
";",
"if",
"(",
"!",
"$",
"response",
"->",
"count",
"(",
")",
")",
"return",
"0",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"row",
"(",
")",
";",
"return",
"intval",
"(",
"$",
"response",
"->",
"numberOfItems",
")",
";",
"}"
] | Return the number of items available in the table
@param string $where
@param string[] $variables
@return integer | [
"Return",
"the",
"number",
"of",
"items",
"available",
"in",
"the",
"table"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L119-L130 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.formatWhereClause | protected function formatWhereClause($where)
{
if (!empty($where)) {
if (stripos($where, 'where') === false || stripos($where, 'select') !== false) {
$where = ' where ' . $where;
}
}
return $where;
} | php | protected function formatWhereClause($where)
{
if (!empty($where)) {
if (stripos($where, 'where') === false || stripos($where, 'select') !== false) {
$where = ' where ' . $where;
}
}
return $where;
} | [
"protected",
"function",
"formatWhereClause",
"(",
"$",
"where",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"where",
")",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"where",
",",
"'where'",
")",
"===",
"false",
"||",
"stripos",
"(",
"$",
"where",
",",
"'select'",
")",
"!==",
"false",
")",
"{",
"$",
"where",
"=",
"' where '",
".",
"$",
"where",
";",
"}",
"}",
"return",
"$",
"where",
";",
"}"
] | Some simple checks for a where clause
@param $where
@return string | [
"Some",
"simple",
"checks",
"for",
"a",
"where",
"clause"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L138-L147 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.fetchAll | public function fetchAll($page, $pagination, $where)
{
$index = ceil(($page - 1) * $pagination);
$where = $this->formatWhereClause($where);
$sql = "
select " . $this->getMappingAsSQL() . "
from " . $this->getTable() . "
" . $where . "
limit " . $index . ',' . intval($pagination) . ";";
$query = $this->driver->query($sql, [], static::DATA_OBJECT_CLASS);
return $query->result();
} | php | public function fetchAll($page, $pagination, $where)
{
$index = ceil(($page - 1) * $pagination);
$where = $this->formatWhereClause($where);
$sql = "
select " . $this->getMappingAsSQL() . "
from " . $this->getTable() . "
" . $where . "
limit " . $index . ',' . intval($pagination) . ";";
$query = $this->driver->query($sql, [], static::DATA_OBJECT_CLASS);
return $query->result();
} | [
"public",
"function",
"fetchAll",
"(",
"$",
"page",
",",
"$",
"pagination",
",",
"$",
"where",
")",
"{",
"$",
"index",
"=",
"ceil",
"(",
"(",
"$",
"page",
"-",
"1",
")",
"*",
"$",
"pagination",
")",
";",
"$",
"where",
"=",
"$",
"this",
"->",
"formatWhereClause",
"(",
"$",
"where",
")",
";",
"$",
"sql",
"=",
"\"\n\t\t\tselect \"",
".",
"$",
"this",
"->",
"getMappingAsSQL",
"(",
")",
".",
"\"\n\t\t\tfrom \"",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"\"\n\t\t\t\"",
".",
"$",
"where",
".",
"\"\n\t\t\tlimit \"",
".",
"$",
"index",
".",
"','",
".",
"intval",
"(",
"$",
"pagination",
")",
".",
"\";\"",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"driver",
"->",
"query",
"(",
"$",
"sql",
",",
"[",
"]",
",",
"static",
"::",
"DATA_OBJECT_CLASS",
")",
";",
"return",
"$",
"query",
"->",
"result",
"(",
")",
";",
"}"
] | Actually fetch all the items with the given params
@param $page
@param $pagination
@param $where
@return \stdClass[] | [
"Actually",
"fetch",
"all",
"the",
"items",
"with",
"the",
"given",
"params"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L171-L186 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.fetchByColumn | protected function fetchByColumn($column, $value)
{
/**
* @var \Slab\Database\Providers\BaseResponse $response
*/
$response = $this->driver->query("select " . $this->getMappingAsSQL() . " from " . $this->getTable() . " where `" . $column . "` = ? limit 1;", array($value), static::DATA_OBJECT_CLASS);
return $response->row();
} | php | protected function fetchByColumn($column, $value)
{
/**
* @var \Slab\Database\Providers\BaseResponse $response
*/
$response = $this->driver->query("select " . $this->getMappingAsSQL() . " from " . $this->getTable() . " where `" . $column . "` = ? limit 1;", array($value), static::DATA_OBJECT_CLASS);
return $response->row();
} | [
"protected",
"function",
"fetchByColumn",
"(",
"$",
"column",
",",
"$",
"value",
")",
"{",
"/**\n * @var \\Slab\\Database\\Providers\\BaseResponse $response\n */",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"query",
"(",
"\"select \"",
".",
"$",
"this",
"->",
"getMappingAsSQL",
"(",
")",
".",
"\" from \"",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"\" where `\"",
".",
"$",
"column",
".",
"\"` = ? limit 1;\"",
",",
"array",
"(",
"$",
"value",
")",
",",
"static",
"::",
"DATA_OBJECT_CLASS",
")",
";",
"return",
"$",
"response",
"->",
"row",
"(",
")",
";",
"}"
] | Do actual mysql query by specific criteria
@param string $column
@param string $value
@return NULL|mixed | [
"Do",
"actual",
"mysql",
"query",
"by",
"specific",
"criteria"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L195-L203 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.getPrimaryKey | public function getPrimaryKey($tableAlias = '')
{
$output = '';
if (!empty($tableAlias)) {
$output .= '`' . $tableAlias . '`.';
}
$output .= '`'.static::ID_COLUMN.'`';
return $output;
} | php | public function getPrimaryKey($tableAlias = '')
{
$output = '';
if (!empty($tableAlias)) {
$output .= '`' . $tableAlias . '`.';
}
$output .= '`'.static::ID_COLUMN.'`';
return $output;
} | [
"public",
"function",
"getPrimaryKey",
"(",
"$",
"tableAlias",
"=",
"''",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tableAlias",
")",
")",
"{",
"$",
"output",
".=",
"'`'",
".",
"$",
"tableAlias",
".",
"'`.'",
";",
"}",
"$",
"output",
".=",
"'`'",
".",
"static",
"::",
"ID_COLUMN",
".",
"'`'",
";",
"return",
"$",
"output",
";",
"}"
] | Return primary key qualified or not
@param string $tableAlias
@return string | [
"Return",
"primary",
"key",
"qualified",
"or",
"not"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L250-L261 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.getColumnsAsSQL | public function getColumnsAsSQL($tableAlias = '', $columnPrefix = '')
{
if (empty($this->mapping)) {
return '*';
}
$output = '';
foreach ($this->mapping as $column => $mappingField) {
if (!empty($output)) {
$output .= ',';
}
if (!empty($tableAlias)) {
$output .= '`' . $tableAlias . '`.';
}
$output .= '`' . $column . '`';
if (!empty($columnPrefix)) {
$output .= ' as `' . $columnPrefix . $column . '`';
}
}
return $output;
} | php | public function getColumnsAsSQL($tableAlias = '', $columnPrefix = '')
{
if (empty($this->mapping)) {
return '*';
}
$output = '';
foreach ($this->mapping as $column => $mappingField) {
if (!empty($output)) {
$output .= ',';
}
if (!empty($tableAlias)) {
$output .= '`' . $tableAlias . '`.';
}
$output .= '`' . $column . '`';
if (!empty($columnPrefix)) {
$output .= ' as `' . $columnPrefix . $column . '`';
}
}
return $output;
} | [
"public",
"function",
"getColumnsAsSQL",
"(",
"$",
"tableAlias",
"=",
"''",
",",
"$",
"columnPrefix",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"mapping",
")",
")",
"{",
"return",
"'*'",
";",
"}",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"mapping",
"as",
"$",
"column",
"=>",
"$",
"mappingField",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"output",
")",
")",
"{",
"$",
"output",
".=",
"','",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"tableAlias",
")",
")",
"{",
"$",
"output",
".=",
"'`'",
".",
"$",
"tableAlias",
".",
"'`.'",
";",
"}",
"$",
"output",
".=",
"'`'",
".",
"$",
"column",
".",
"'`'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"columnPrefix",
")",
")",
"{",
"$",
"output",
".=",
"' as `'",
".",
"$",
"columnPrefix",
".",
"$",
"column",
".",
"'`'",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Get raw columns as SQL, with some prefix options
@param string $tableAlias
@param string $columnPrefix
@return string | [
"Get",
"raw",
"columns",
"as",
"SQL",
"with",
"some",
"prefix",
"options"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L270-L294 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.resetMappingOptions | protected function resetMappingOptions()
{
$this->mappingOptions = new \stdClass();
$this->mappingOptions->destructiveMapping = false;
$this->mappingOptions->assignNonMappedColumns = true;
$this->mappingOptions->fieldPrefix = '';
$this->mappingOptions->throwOnEmptyId = false;
$this->mappingOptions->mapUnmappedColumns = true;
} | php | protected function resetMappingOptions()
{
$this->mappingOptions = new \stdClass();
$this->mappingOptions->destructiveMapping = false;
$this->mappingOptions->assignNonMappedColumns = true;
$this->mappingOptions->fieldPrefix = '';
$this->mappingOptions->throwOnEmptyId = false;
$this->mappingOptions->mapUnmappedColumns = true;
} | [
"protected",
"function",
"resetMappingOptions",
"(",
")",
"{",
"$",
"this",
"->",
"mappingOptions",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"destructiveMapping",
"=",
"false",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"assignNonMappedColumns",
"=",
"true",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"fieldPrefix",
"=",
"''",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"throwOnEmptyId",
"=",
"false",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"mapUnmappedColumns",
"=",
"true",
";",
"}"
] | Reset mapping options | [
"Reset",
"mapping",
"options"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L299-L307 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.setDestructiveMapping | public function setDestructiveMapping($destructiveMapping)
{
if (empty($this->mappingOptions)) $this->resetMappingOptions();
$this->mappingOptions->destructiveMapping = $destructiveMapping;
return $this;
} | php | public function setDestructiveMapping($destructiveMapping)
{
if (empty($this->mappingOptions)) $this->resetMappingOptions();
$this->mappingOptions->destructiveMapping = $destructiveMapping;
return $this;
} | [
"public",
"function",
"setDestructiveMapping",
"(",
"$",
"destructiveMapping",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"mappingOptions",
")",
")",
"$",
"this",
"->",
"resetMappingOptions",
"(",
")",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"destructiveMapping",
"=",
"$",
"destructiveMapping",
";",
"return",
"$",
"this",
";",
"}"
] | Set destructive mapping option
@param $destructiveMapping
@return $this | [
"Set",
"destructive",
"mapping",
"option"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L328-L335 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.setAssignNonMappedColumns | public function setAssignNonMappedColumns($assignNonMappedColumns)
{
if (empty($this->mappingOptions)) $this->resetMappingOptions();
$this->mappingOptions->assignNonMappedColumns = $assignNonMappedColumns;
return $this;
} | php | public function setAssignNonMappedColumns($assignNonMappedColumns)
{
if (empty($this->mappingOptions)) $this->resetMappingOptions();
$this->mappingOptions->assignNonMappedColumns = $assignNonMappedColumns;
return $this;
} | [
"public",
"function",
"setAssignNonMappedColumns",
"(",
"$",
"assignNonMappedColumns",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"mappingOptions",
")",
")",
"$",
"this",
"->",
"resetMappingOptions",
"(",
")",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"assignNonMappedColumns",
"=",
"$",
"assignNonMappedColumns",
";",
"return",
"$",
"this",
";",
"}"
] | Set flag for assigning non-mapped columns
@param $assignNonMappedColumns
@return $this | [
"Set",
"flag",
"for",
"assigning",
"non",
"-",
"mapped",
"columns"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L343-L350 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.setFieldPrefix | public function setFieldPrefix($fieldPrefix)
{
if (empty($this->mappingOptions)) $this->resetMappingOptions();
$this->mappingOptions->fieldPrefix = $fieldPrefix;
return $this;
} | php | public function setFieldPrefix($fieldPrefix)
{
if (empty($this->mappingOptions)) $this->resetMappingOptions();
$this->mappingOptions->fieldPrefix = $fieldPrefix;
return $this;
} | [
"public",
"function",
"setFieldPrefix",
"(",
"$",
"fieldPrefix",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"mappingOptions",
")",
")",
"$",
"this",
"->",
"resetMappingOptions",
"(",
")",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"fieldPrefix",
"=",
"$",
"fieldPrefix",
";",
"return",
"$",
"this",
";",
"}"
] | Set mapping option field prefix
@param $fieldPrefix
@return $this | [
"Set",
"mapping",
"option",
"field",
"prefix"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L358-L365 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.setThrowIfEmptyId | public function setThrowIfEmptyId($throwOnEmptyId)
{
if (empty($this->mappingOptions)) $this->resetMappingOptions();
$this->mappingOptions->throwOnEmptyId = $throwOnEmptyId;
return $this;
} | php | public function setThrowIfEmptyId($throwOnEmptyId)
{
if (empty($this->mappingOptions)) $this->resetMappingOptions();
$this->mappingOptions->throwOnEmptyId = $throwOnEmptyId;
return $this;
} | [
"public",
"function",
"setThrowIfEmptyId",
"(",
"$",
"throwOnEmptyId",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"mappingOptions",
")",
")",
"$",
"this",
"->",
"resetMappingOptions",
"(",
")",
";",
"$",
"this",
"->",
"mappingOptions",
"->",
"throwOnEmptyId",
"=",
"$",
"throwOnEmptyId",
";",
"return",
"$",
"this",
";",
"}"
] | Throw an exception if the main id doesn't get mapped?
@param $throwOnEmptyId
@return $this | [
"Throw",
"an",
"exception",
"if",
"the",
"main",
"id",
"doesn",
"t",
"get",
"mapped?"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L373-L380 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.mapObject | protected function mapObject($databaseResult)
{
foreach ($databaseResult as $column => $value) {
if (!empty($this->mapping[$column])) {
list($variable, $modifier) = $this->splitVariableWithModifier($this->mapping[$column]);
$this->$variable = $this->getMappedValue($databaseResult, $column, $this->mapping[$column]);
} else {
$this->$column = $value;
}
}
} | php | protected function mapObject($databaseResult)
{
foreach ($databaseResult as $column => $value) {
if (!empty($this->mapping[$column])) {
list($variable, $modifier) = $this->splitVariableWithModifier($this->mapping[$column]);
$this->$variable = $this->getMappedValue($databaseResult, $column, $this->mapping[$column]);
} else {
$this->$column = $value;
}
}
} | [
"protected",
"function",
"mapObject",
"(",
"$",
"databaseResult",
")",
"{",
"foreach",
"(",
"$",
"databaseResult",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"mapping",
"[",
"$",
"column",
"]",
")",
")",
"{",
"list",
"(",
"$",
"variable",
",",
"$",
"modifier",
")",
"=",
"$",
"this",
"->",
"splitVariableWithModifier",
"(",
"$",
"this",
"->",
"mapping",
"[",
"$",
"column",
"]",
")",
";",
"$",
"this",
"->",
"$",
"variable",
"=",
"$",
"this",
"->",
"getMappedValue",
"(",
"$",
"databaseResult",
",",
"$",
"column",
",",
"$",
"this",
"->",
"mapping",
"[",
"$",
"column",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"$",
"column",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Map a single object to this instance
@param \stdClass $databaseResult | [
"Map",
"a",
"single",
"object",
"to",
"this",
"instance"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L387-L398 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.splitVariableWithModifier | protected function splitVariableWithModifier($column)
{
$modifier = false;
if (strpos($column, ':') !== false) {
return explode(':', $column);
}
return [$column, false];
} | php | protected function splitVariableWithModifier($column)
{
$modifier = false;
if (strpos($column, ':') !== false) {
return explode(':', $column);
}
return [$column, false];
} | [
"protected",
"function",
"splitVariableWithModifier",
"(",
"$",
"column",
")",
"{",
"$",
"modifier",
"=",
"false",
";",
"if",
"(",
"strpos",
"(",
"$",
"column",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"return",
"explode",
"(",
"':'",
",",
"$",
"column",
")",
";",
"}",
"return",
"[",
"$",
"column",
",",
"false",
"]",
";",
"}"
] | Splits variable with a modifier
@param string $column
@return array | [
"Splits",
"variable",
"with",
"a",
"modifier"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L454-L462 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.modifierDate | protected function modifierDate($input)
{
if (empty($input)) return NULL;
//if ($input == '0000-00-00 00:00:00') return NULL;
if ($input instanceof \DateTime) return $input;
try {
$output = new \DateTime($input);
$output->setTimeZone(new \DateTimeZone('America/New_York'));
return $output;
} catch (\Exception $exception) {
if (!empty($this->log)) $this->log->error('Failed to convert \DateTime object from string "' . $input . '"', $exception);
}
return NULL;
} | php | protected function modifierDate($input)
{
if (empty($input)) return NULL;
//if ($input == '0000-00-00 00:00:00') return NULL;
if ($input instanceof \DateTime) return $input;
try {
$output = new \DateTime($input);
$output->setTimeZone(new \DateTimeZone('America/New_York'));
return $output;
} catch (\Exception $exception) {
if (!empty($this->log)) $this->log->error('Failed to convert \DateTime object from string "' . $input . '"', $exception);
}
return NULL;
} | [
"protected",
"function",
"modifierDate",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"input",
")",
")",
"return",
"NULL",
";",
"//if ($input == '0000-00-00 00:00:00') return NULL;",
"if",
"(",
"$",
"input",
"instanceof",
"\\",
"DateTime",
")",
"return",
"$",
"input",
";",
"try",
"{",
"$",
"output",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"input",
")",
";",
"$",
"output",
"->",
"setTimeZone",
"(",
"new",
"\\",
"DateTimeZone",
"(",
"'America/New_York'",
")",
")",
";",
"return",
"$",
"output",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"log",
")",
")",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"'Failed to convert \\DateTime object from string \"'",
".",
"$",
"input",
".",
"'\"'",
",",
"$",
"exception",
")",
";",
"}",
"return",
"NULL",
";",
"}"
] | Return a date time modified input
@param string $input
@return \DateTime|NULL | [
"Return",
"a",
"date",
"time",
"modified",
"input"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L493-L510 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.modifierTimezone | protected function modifierTimezone($input)
{
if ($input instanceof \DateTimeZone) return $input;
try {
$output = new \DateTimeZone($input);
return $output;
} catch (\Exception $exception) {
if (!empty($this->log)) $this->log->error("Failed to convert \\DateTimeZone object from string " . $input);
}
return NULL;
} | php | protected function modifierTimezone($input)
{
if ($input instanceof \DateTimeZone) return $input;
try {
$output = new \DateTimeZone($input);
return $output;
} catch (\Exception $exception) {
if (!empty($this->log)) $this->log->error("Failed to convert \\DateTimeZone object from string " . $input);
}
return NULL;
} | [
"protected",
"function",
"modifierTimezone",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"$",
"input",
"instanceof",
"\\",
"DateTimeZone",
")",
"return",
"$",
"input",
";",
"try",
"{",
"$",
"output",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"input",
")",
";",
"return",
"$",
"output",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"log",
")",
")",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"\"Failed to convert \\\\DateTimeZone object from string \"",
".",
"$",
"input",
")",
";",
"}",
"return",
"NULL",
";",
"}"
] | Return a timezone modified input
@param string $input
@return \DateTimeZone|NULL | [
"Return",
"a",
"timezone",
"modified",
"input"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L518-L531 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.buildModel | public function buildModel($databaseResult = null)
{
$this->resetMappingOptions();
if (empty($databaseResult)) return;
$this->mapObject($databaseResult);
} | php | public function buildModel($databaseResult = null)
{
$this->resetMappingOptions();
if (empty($databaseResult)) return;
$this->mapObject($databaseResult);
} | [
"public",
"function",
"buildModel",
"(",
"$",
"databaseResult",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"resetMappingOptions",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"databaseResult",
")",
")",
"return",
";",
"$",
"this",
"->",
"mapObject",
"(",
"$",
"databaseResult",
")",
";",
"}"
] | Map the object to itself
@param \stdClass $databaseResult - The database result to map
@param bool $assignNonMappedColumns - Leave fields that aren't mapped in the output object
@param bool $destructiveMapping - Remove field from databaseResult upon mapping
@param string $fieldPrefix - An optional prefix for fields inc ase you are doing multiple joins | [
"Map",
"the",
"object",
"to",
"itself"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L541-L548 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.performMappingOnObject | public function performMappingOnObject(DataObject $object)
{
//By default, we already have our data mapped in the object (hopefully properly)
//But we do need to convert things that may need converting
foreach ($this->mapping as $field => $variable) {
$modifier = false;
$newField = $variable;
if (strpos($variable, ':') !== false) {
list($newField, $modifier) = explode(':', $variable);
$object->$newField = $this->getMappedValue($object, $newField, $variable);
}
}
} | php | public function performMappingOnObject(DataObject $object)
{
//By default, we already have our data mapped in the object (hopefully properly)
//But we do need to convert things that may need converting
foreach ($this->mapping as $field => $variable) {
$modifier = false;
$newField = $variable;
if (strpos($variable, ':') !== false) {
list($newField, $modifier) = explode(':', $variable);
$object->$newField = $this->getMappedValue($object, $newField, $variable);
}
}
} | [
"public",
"function",
"performMappingOnObject",
"(",
"DataObject",
"$",
"object",
")",
"{",
"//By default, we already have our data mapped in the object (hopefully properly)",
"//But we do need to convert things that may need converting",
"foreach",
"(",
"$",
"this",
"->",
"mapping",
"as",
"$",
"field",
"=>",
"$",
"variable",
")",
"{",
"$",
"modifier",
"=",
"false",
";",
"$",
"newField",
"=",
"$",
"variable",
";",
"if",
"(",
"strpos",
"(",
"$",
"variable",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"newField",
",",
"$",
"modifier",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"variable",
")",
";",
"$",
"object",
"->",
"$",
"newField",
"=",
"$",
"this",
"->",
"getMappedValue",
"(",
"$",
"object",
",",
"$",
"newField",
",",
"$",
"variable",
")",
";",
"}",
"}",
"}"
] | Array walk function, overridable
The response object will automatically try to fire this when pulling a list of automapped objects.
@param DataObject $Object | [
"Array",
"walk",
"function",
"overridable"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L557-L570 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.insertObject | public function insertObject(DataObject $object, $skipID = true)
{
$data = [];
foreach ($this->mapping as $column => $local) {
if ($skipID && ($column == static::ID_COLUMN)) continue;
$modifier = false;
if (strpos($local, ':') !== false) {
list($local, $modifier) = explode(':', $local);
}
if (!empty($object->$local)) {
if (!empty($modifier) && is_object($this->$local)) {
switch ($modifier) {
case 'datetime':
case 'date':
$data[$column] = $object->$local->format('Y-m-d H:i:s');
break;
case 'timezone':
$data[$column] = $object->$local->getName();
break;
}
} else {
$data[$column] = $object->$local;
}
}
}
if (!empty($data)) {
$this->driver->insert(static::TABLE_NAME, $data);
/**
* @var \Slab\Database\Providers\MySQL\Provider $mysqlDriver
*/
$mysqlDriver = $this->driver->getProvider();
$object->{static::ID_COLUMN} = $mysqlDriver->insertId();
return $object->{static::ID_COLUMN};
}
return false;
} | php | public function insertObject(DataObject $object, $skipID = true)
{
$data = [];
foreach ($this->mapping as $column => $local) {
if ($skipID && ($column == static::ID_COLUMN)) continue;
$modifier = false;
if (strpos($local, ':') !== false) {
list($local, $modifier) = explode(':', $local);
}
if (!empty($object->$local)) {
if (!empty($modifier) && is_object($this->$local)) {
switch ($modifier) {
case 'datetime':
case 'date':
$data[$column] = $object->$local->format('Y-m-d H:i:s');
break;
case 'timezone':
$data[$column] = $object->$local->getName();
break;
}
} else {
$data[$column] = $object->$local;
}
}
}
if (!empty($data)) {
$this->driver->insert(static::TABLE_NAME, $data);
/**
* @var \Slab\Database\Providers\MySQL\Provider $mysqlDriver
*/
$mysqlDriver = $this->driver->getProvider();
$object->{static::ID_COLUMN} = $mysqlDriver->insertId();
return $object->{static::ID_COLUMN};
}
return false;
} | [
"public",
"function",
"insertObject",
"(",
"DataObject",
"$",
"object",
",",
"$",
"skipID",
"=",
"true",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"mapping",
"as",
"$",
"column",
"=>",
"$",
"local",
")",
"{",
"if",
"(",
"$",
"skipID",
"&&",
"(",
"$",
"column",
"==",
"static",
"::",
"ID_COLUMN",
")",
")",
"continue",
";",
"$",
"modifier",
"=",
"false",
";",
"if",
"(",
"strpos",
"(",
"$",
"local",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"local",
",",
"$",
"modifier",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"local",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"object",
"->",
"$",
"local",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"modifier",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"$",
"local",
")",
")",
"{",
"switch",
"(",
"$",
"modifier",
")",
"{",
"case",
"'datetime'",
":",
"case",
"'date'",
":",
"$",
"data",
"[",
"$",
"column",
"]",
"=",
"$",
"object",
"->",
"$",
"local",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"break",
";",
"case",
"'timezone'",
":",
"$",
"data",
"[",
"$",
"column",
"]",
"=",
"$",
"object",
"->",
"$",
"local",
"->",
"getName",
"(",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"column",
"]",
"=",
"$",
"object",
"->",
"$",
"local",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"driver",
"->",
"insert",
"(",
"static",
"::",
"TABLE_NAME",
",",
"$",
"data",
")",
";",
"/**\n * @var \\Slab\\Database\\Providers\\MySQL\\Provider $mysqlDriver\n */",
"$",
"mysqlDriver",
"=",
"$",
"this",
"->",
"driver",
"->",
"getProvider",
"(",
")",
";",
"$",
"object",
"->",
"{",
"static",
"::",
"ID_COLUMN",
"}",
"=",
"$",
"mysqlDriver",
"->",
"insertId",
"(",
")",
";",
"return",
"$",
"object",
"->",
"{",
"static",
"::",
"ID_COLUMN",
"}",
";",
"}",
"return",
"false",
";",
"}"
] | Attempts to insert the object into the table
@param DataObject $object
@param boolean $skipID
@return bool|\Slab\Database\Providers\BaseResponse | [
"Attempts",
"to",
"insert",
"the",
"object",
"into",
"the",
"table"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L589-L634 | train |
SlabPHP/database | src/Models/MySQL/Loader.php | Loader.getUnmappedArray | public function getUnmappedArray(DataObject $object)
{
$output = [];
foreach ($this->mapping as $unmappedField => $mappedField) {
if (strpos($mappedField, ':') !== false) {
list($mappedField, $modifier) = explode(':', $mappedField);
}
$output[$unmappedField] = $object->{$mappedField};
}
return $output;
} | php | public function getUnmappedArray(DataObject $object)
{
$output = [];
foreach ($this->mapping as $unmappedField => $mappedField) {
if (strpos($mappedField, ':') !== false) {
list($mappedField, $modifier) = explode(':', $mappedField);
}
$output[$unmappedField] = $object->{$mappedField};
}
return $output;
} | [
"public",
"function",
"getUnmappedArray",
"(",
"DataObject",
"$",
"object",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"mapping",
"as",
"$",
"unmappedField",
"=>",
"$",
"mappedField",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"mappedField",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"mappedField",
",",
"$",
"modifier",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"mappedField",
")",
";",
"}",
"$",
"output",
"[",
"$",
"unmappedField",
"]",
"=",
"$",
"object",
"->",
"{",
"$",
"mappedField",
"}",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Return an array of an object as an unmapped aray, useful for dumping defaults
@return array | [
"Return",
"an",
"array",
"of",
"an",
"object",
"as",
"an",
"unmapped",
"aray",
"useful",
"for",
"dumping",
"defaults"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Loader.php#L641-L654 | train |
togucms/TemplateBundle | Loader/FilesystemLoader.php | FilesystemLoader.findFilename | public function findFilename($name) {
$logicalName = (string) $name;
if(isset($this->cache[$logicalName])) {
return $this->cache[$logicalName];
}
try {
$template = $this->parser->parse($name);
$file = $this->locator->locate($template);
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', $logicalName));
}
return $this->cache[$logicalName] = $file;
} | php | public function findFilename($name) {
$logicalName = (string) $name;
if(isset($this->cache[$logicalName])) {
return $this->cache[$logicalName];
}
try {
$template = $this->parser->parse($name);
$file = $this->locator->locate($template);
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', $logicalName));
}
return $this->cache[$logicalName] = $file;
} | [
"public",
"function",
"findFilename",
"(",
"$",
"name",
")",
"{",
"$",
"logicalName",
"=",
"(",
"string",
")",
"$",
"name",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"logicalName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"[",
"$",
"logicalName",
"]",
";",
"}",
"try",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"$",
"name",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"locator",
"->",
"locate",
"(",
"$",
"template",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unable to find template \"%s\".'",
",",
"$",
"logicalName",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cache",
"[",
"$",
"logicalName",
"]",
"=",
"$",
"file",
";",
"}"
] | Helper function for getting a template file name.
@param string $name
@return string Template file name | [
"Helper",
"function",
"for",
"getting",
"a",
"template",
"file",
"name",
"."
] | b07d3bff948d547e95f81154503dfa3a333eef64 | https://github.com/togucms/TemplateBundle/blob/b07d3bff948d547e95f81154503dfa3a333eef64/Loader/FilesystemLoader.php#L57-L71 | train |
koolkode/security | src/Cipher/Cipher.php | Cipher.decryptMessage | public function decryptMessage($message)
{
$calgo = $this->config->getCipherAlgorithm();
$cmode = $this->config->getCipherMode();
$malgo = $this->config->getHmacAlgorithm();
$size = mcrypt_get_iv_size($calgo, $cmode);
$keySize = mcrypt_get_key_size($calgo, $cmode);
$hmacSize = strlen(hash_hmac($malgo, '', 'foo-key', true));
$cmac = substr($message, -1 * $hmacSize);
$iv = substr($message, 0, $size);
$cipherText = substr($message, $size, -1 * $hmacSize);
$hmac = hash_hmac($malgo, $iv . $cipherText, $this->computeCipherKey($this->config->getHmacKey(), $hmacSize, $iv), true);
if(!SecurityUtil::timingSafeEquals($hmac, $cmac))
{
throw new IntegrityCheckFailedException('Invalid encrypted input message detected');
}
$key = $this->computeCipherKey($this->config->getCipherKey(), $keySize, $iv);
$data = mcrypt_decrypt($calgo, $key, $cipherText, $cmode, $iv);
// PKCS7 Padding
$pad = ord($data[strlen($data) - 1]);
$data = substr($data, 0, -1 * $pad);
// Remove zero-byte padding from the string.
return $data;
} | php | public function decryptMessage($message)
{
$calgo = $this->config->getCipherAlgorithm();
$cmode = $this->config->getCipherMode();
$malgo = $this->config->getHmacAlgorithm();
$size = mcrypt_get_iv_size($calgo, $cmode);
$keySize = mcrypt_get_key_size($calgo, $cmode);
$hmacSize = strlen(hash_hmac($malgo, '', 'foo-key', true));
$cmac = substr($message, -1 * $hmacSize);
$iv = substr($message, 0, $size);
$cipherText = substr($message, $size, -1 * $hmacSize);
$hmac = hash_hmac($malgo, $iv . $cipherText, $this->computeCipherKey($this->config->getHmacKey(), $hmacSize, $iv), true);
if(!SecurityUtil::timingSafeEquals($hmac, $cmac))
{
throw new IntegrityCheckFailedException('Invalid encrypted input message detected');
}
$key = $this->computeCipherKey($this->config->getCipherKey(), $keySize, $iv);
$data = mcrypt_decrypt($calgo, $key, $cipherText, $cmode, $iv);
// PKCS7 Padding
$pad = ord($data[strlen($data) - 1]);
$data = substr($data, 0, -1 * $pad);
// Remove zero-byte padding from the string.
return $data;
} | [
"public",
"function",
"decryptMessage",
"(",
"$",
"message",
")",
"{",
"$",
"calgo",
"=",
"$",
"this",
"->",
"config",
"->",
"getCipherAlgorithm",
"(",
")",
";",
"$",
"cmode",
"=",
"$",
"this",
"->",
"config",
"->",
"getCipherMode",
"(",
")",
";",
"$",
"malgo",
"=",
"$",
"this",
"->",
"config",
"->",
"getHmacAlgorithm",
"(",
")",
";",
"$",
"size",
"=",
"mcrypt_get_iv_size",
"(",
"$",
"calgo",
",",
"$",
"cmode",
")",
";",
"$",
"keySize",
"=",
"mcrypt_get_key_size",
"(",
"$",
"calgo",
",",
"$",
"cmode",
")",
";",
"$",
"hmacSize",
"=",
"strlen",
"(",
"hash_hmac",
"(",
"$",
"malgo",
",",
"''",
",",
"'foo-key'",
",",
"true",
")",
")",
";",
"$",
"cmac",
"=",
"substr",
"(",
"$",
"message",
",",
"-",
"1",
"*",
"$",
"hmacSize",
")",
";",
"$",
"iv",
"=",
"substr",
"(",
"$",
"message",
",",
"0",
",",
"$",
"size",
")",
";",
"$",
"cipherText",
"=",
"substr",
"(",
"$",
"message",
",",
"$",
"size",
",",
"-",
"1",
"*",
"$",
"hmacSize",
")",
";",
"$",
"hmac",
"=",
"hash_hmac",
"(",
"$",
"malgo",
",",
"$",
"iv",
".",
"$",
"cipherText",
",",
"$",
"this",
"->",
"computeCipherKey",
"(",
"$",
"this",
"->",
"config",
"->",
"getHmacKey",
"(",
")",
",",
"$",
"hmacSize",
",",
"$",
"iv",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"SecurityUtil",
"::",
"timingSafeEquals",
"(",
"$",
"hmac",
",",
"$",
"cmac",
")",
")",
"{",
"throw",
"new",
"IntegrityCheckFailedException",
"(",
"'Invalid encrypted input message detected'",
")",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"computeCipherKey",
"(",
"$",
"this",
"->",
"config",
"->",
"getCipherKey",
"(",
")",
",",
"$",
"keySize",
",",
"$",
"iv",
")",
";",
"$",
"data",
"=",
"mcrypt_decrypt",
"(",
"$",
"calgo",
",",
"$",
"key",
",",
"$",
"cipherText",
",",
"$",
"cmode",
",",
"$",
"iv",
")",
";",
"// PKCS7 Padding\r",
"$",
"pad",
"=",
"ord",
"(",
"$",
"data",
"[",
"strlen",
"(",
"$",
"data",
")",
"-",
"1",
"]",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"-",
"1",
"*",
"$",
"pad",
")",
";",
"// Remove zero-byte padding from the string.\r",
"return",
"$",
"data",
";",
"}"
] | Decrypts a message with auhtenticity check.
@param string $message Encoded message.
@return mixed Plaintext message.
@throws IntegrityCheckFailedException | [
"Decrypts",
"a",
"message",
"with",
"auhtenticity",
"check",
"."
] | d3d8d42392f520754847d29b6df19aaa38c79e8e | https://github.com/koolkode/security/blob/d3d8d42392f520754847d29b6df19aaa38c79e8e/src/Cipher/Cipher.php#L39-L68 | train |
koolkode/security | src/Cipher/Cipher.php | Cipher.encryptMessage | public function encryptMessage($input)
{
$input = (string)$input;
$calgo = $this->config->getCipherAlgorithm();
$cmode = $this->config->getCipherMode();
$malgo = $this->config->getHmacAlgorithm();
$size = mcrypt_get_iv_size($calgo, $cmode);
$keySize = mcrypt_get_key_size($calgo, $cmode);
$blockSize = mcrypt_get_block_size($calgo, $cmode);
$hmacSize = strlen(hash_hmac($malgo, '', 'foo-key', true));
$iv = random_bytes($size);
$key = $this->computeCipherKey($this->config->getCipherKey(), $keySize, $iv);
// PKCS7 Padding
$pad = $blockSize - (strlen($input) % $blockSize);
$input .= str_repeat(chr($pad), $pad);
$cipherText = $iv . mcrypt_encrypt($calgo, $key, $input, $cmode, $iv);
return $cipherText . hash_hmac($malgo, $cipherText, $this->computeCipherKey($this->config->getHmacKey(), $hmacSize, $iv), true);
} | php | public function encryptMessage($input)
{
$input = (string)$input;
$calgo = $this->config->getCipherAlgorithm();
$cmode = $this->config->getCipherMode();
$malgo = $this->config->getHmacAlgorithm();
$size = mcrypt_get_iv_size($calgo, $cmode);
$keySize = mcrypt_get_key_size($calgo, $cmode);
$blockSize = mcrypt_get_block_size($calgo, $cmode);
$hmacSize = strlen(hash_hmac($malgo, '', 'foo-key', true));
$iv = random_bytes($size);
$key = $this->computeCipherKey($this->config->getCipherKey(), $keySize, $iv);
// PKCS7 Padding
$pad = $blockSize - (strlen($input) % $blockSize);
$input .= str_repeat(chr($pad), $pad);
$cipherText = $iv . mcrypt_encrypt($calgo, $key, $input, $cmode, $iv);
return $cipherText . hash_hmac($malgo, $cipherText, $this->computeCipherKey($this->config->getHmacKey(), $hmacSize, $iv), true);
} | [
"public",
"function",
"encryptMessage",
"(",
"$",
"input",
")",
"{",
"$",
"input",
"=",
"(",
"string",
")",
"$",
"input",
";",
"$",
"calgo",
"=",
"$",
"this",
"->",
"config",
"->",
"getCipherAlgorithm",
"(",
")",
";",
"$",
"cmode",
"=",
"$",
"this",
"->",
"config",
"->",
"getCipherMode",
"(",
")",
";",
"$",
"malgo",
"=",
"$",
"this",
"->",
"config",
"->",
"getHmacAlgorithm",
"(",
")",
";",
"$",
"size",
"=",
"mcrypt_get_iv_size",
"(",
"$",
"calgo",
",",
"$",
"cmode",
")",
";",
"$",
"keySize",
"=",
"mcrypt_get_key_size",
"(",
"$",
"calgo",
",",
"$",
"cmode",
")",
";",
"$",
"blockSize",
"=",
"mcrypt_get_block_size",
"(",
"$",
"calgo",
",",
"$",
"cmode",
")",
";",
"$",
"hmacSize",
"=",
"strlen",
"(",
"hash_hmac",
"(",
"$",
"malgo",
",",
"''",
",",
"'foo-key'",
",",
"true",
")",
")",
";",
"$",
"iv",
"=",
"random_bytes",
"(",
"$",
"size",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"computeCipherKey",
"(",
"$",
"this",
"->",
"config",
"->",
"getCipherKey",
"(",
")",
",",
"$",
"keySize",
",",
"$",
"iv",
")",
";",
"// PKCS7 Padding\r",
"$",
"pad",
"=",
"$",
"blockSize",
"-",
"(",
"strlen",
"(",
"$",
"input",
")",
"%",
"$",
"blockSize",
")",
";",
"$",
"input",
".=",
"str_repeat",
"(",
"chr",
"(",
"$",
"pad",
")",
",",
"$",
"pad",
")",
";",
"$",
"cipherText",
"=",
"$",
"iv",
".",
"mcrypt_encrypt",
"(",
"$",
"calgo",
",",
"$",
"key",
",",
"$",
"input",
",",
"$",
"cmode",
",",
"$",
"iv",
")",
";",
"return",
"$",
"cipherText",
".",
"hash_hmac",
"(",
"$",
"malgo",
",",
"$",
"cipherText",
",",
"$",
"this",
"->",
"computeCipherKey",
"(",
"$",
"this",
"->",
"config",
"->",
"getHmacKey",
"(",
")",
",",
"$",
"hmacSize",
",",
"$",
"iv",
")",
",",
"true",
")",
";",
"}"
] | Encrypts the given message and adds an authenticity code.
<pre><b>CIPHERTEXT</b> := IV + ENCRYPT(CLEARTEXT, PBKDF(ENCRYPTION_KEY))
<b>MESSAGE</b> := CIPHERTEXT + HMAC(CIPHERTEXT, PBKDF(HMAC_KEY))
</pre>
@param string $input Plaintext message.
@return string Encrypted message. | [
"Encrypts",
"the",
"given",
"message",
"and",
"adds",
"an",
"authenticity",
"code",
"."
] | d3d8d42392f520754847d29b6df19aaa38c79e8e | https://github.com/koolkode/security/blob/d3d8d42392f520754847d29b6df19aaa38c79e8e/src/Cipher/Cipher.php#L80-L103 | train |
ptlis/grep-db | src/Search/Result/RowSearchResult.php | RowSearchResult.getColumnResult | public function getColumnResult(string $columnName): FieldSearchResult
{
if (!$this->hasColumnResult($columnName)) {
throw new \RuntimeException('Could not find changed column named "' . $columnName . '"');
}
return $this->fieldMatchList[$columnName];
} | php | public function getColumnResult(string $columnName): FieldSearchResult
{
if (!$this->hasColumnResult($columnName)) {
throw new \RuntimeException('Could not find changed column named "' . $columnName . '"');
}
return $this->fieldMatchList[$columnName];
} | [
"public",
"function",
"getColumnResult",
"(",
"string",
"$",
"columnName",
")",
":",
"FieldSearchResult",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasColumnResult",
"(",
"$",
"columnName",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Could not find changed column named \"'",
".",
"$",
"columnName",
".",
"'\"'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"fieldMatchList",
"[",
"$",
"columnName",
"]",
";",
"}"
] | Returns the column result matching the passed name. | [
"Returns",
"the",
"column",
"result",
"matching",
"the",
"passed",
"name",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Search/Result/RowSearchResult.php#L78-L85 | train |
prosoftSolutions/Pager | DependencyInjection/WhiteOctoberPagerfantaExtension.php | WhiteOctoberPagerfantaExtension.load | public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$processor = new Processor();
$config = $processor->processConfiguration($configuration, $configs);
$container->setParameter('white_october_pagerfanta.default_view', $config['default_view']);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('pagerfanta.xml');
if ($config['exceptions_strategy']['out_of_range_page'] == Configuration::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND) {
$convertListener = $container->getDefinition('pagerfanta.convert_not_valid_max_per_page_to_not_found_listener');
$convertListener->addTag('kernel.event_subscriber');
}
if ($config['exceptions_strategy']['not_valid_current_page'] == Configuration::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND) {
$convertListener = $container->getDefinition('pagerfanta.convert_not_valid_current_page_to_not_found_listener');
$convertListener->addTag('kernel.event_subscriber');
}
} | php | public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$processor = new Processor();
$config = $processor->processConfiguration($configuration, $configs);
$container->setParameter('white_october_pagerfanta.default_view', $config['default_view']);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('pagerfanta.xml');
if ($config['exceptions_strategy']['out_of_range_page'] == Configuration::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND) {
$convertListener = $container->getDefinition('pagerfanta.convert_not_valid_max_per_page_to_not_found_listener');
$convertListener->addTag('kernel.event_subscriber');
}
if ($config['exceptions_strategy']['not_valid_current_page'] == Configuration::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND) {
$convertListener = $container->getDefinition('pagerfanta.convert_not_valid_current_page_to_not_found_listener');
$convertListener->addTag('kernel.event_subscriber');
}
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"configuration",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"processor",
"=",
"new",
"Processor",
"(",
")",
";",
"$",
"config",
"=",
"$",
"processor",
"->",
"processConfiguration",
"(",
"$",
"configuration",
",",
"$",
"configs",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'white_october_pagerfanta.default_view'",
",",
"$",
"config",
"[",
"'default_view'",
"]",
")",
";",
"$",
"loader",
"=",
"new",
"XmlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'pagerfanta.xml'",
")",
";",
"if",
"(",
"$",
"config",
"[",
"'exceptions_strategy'",
"]",
"[",
"'out_of_range_page'",
"]",
"==",
"Configuration",
"::",
"EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND",
")",
"{",
"$",
"convertListener",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'pagerfanta.convert_not_valid_max_per_page_to_not_found_listener'",
")",
";",
"$",
"convertListener",
"->",
"addTag",
"(",
"'kernel.event_subscriber'",
")",
";",
"}",
"if",
"(",
"$",
"config",
"[",
"'exceptions_strategy'",
"]",
"[",
"'not_valid_current_page'",
"]",
"==",
"Configuration",
"::",
"EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND",
")",
"{",
"$",
"convertListener",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'pagerfanta.convert_not_valid_current_page_to_not_found_listener'",
")",
";",
"$",
"convertListener",
"->",
"addTag",
"(",
"'kernel.event_subscriber'",
")",
";",
"}",
"}"
] | Responds to the "white_october_pagerfanta" configuration parameter.
@param array $configs
@param ContainerBuilder $container | [
"Responds",
"to",
"the",
"white_october_pagerfanta",
"configuration",
"parameter",
"."
] | 96446ee22caedc0b9bb486d9ffe7a50b6c13177f | https://github.com/prosoftSolutions/Pager/blob/96446ee22caedc0b9bb486d9ffe7a50b6c13177f/DependencyInjection/WhiteOctoberPagerfantaExtension.php#L33-L53 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Expression/Condition/Logical/Logical.php | Logical.getAttributeConditions | public function getAttributeConditions($attributeName, $unindexablePredicates = false)
{
return array_filter(
$this->parts,
function (Condition $part) use ($attributeName, $unindexablePredicates) {
if ($part instanceof self) {
return $part->getAttributeConditions($attributeName, $unindexablePredicates);
}
return !$unindexablePredicates && in_array($attributeName, $part->getAttributes());
}
);
} | php | public function getAttributeConditions($attributeName, $unindexablePredicates = false)
{
return array_filter(
$this->parts,
function (Condition $part) use ($attributeName, $unindexablePredicates) {
if ($part instanceof self) {
return $part->getAttributeConditions($attributeName, $unindexablePredicates);
}
return !$unindexablePredicates && in_array($attributeName, $part->getAttributes());
}
);
} | [
"public",
"function",
"getAttributeConditions",
"(",
"$",
"attributeName",
",",
"$",
"unindexablePredicates",
"=",
"false",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"parts",
",",
"function",
"(",
"Condition",
"$",
"part",
")",
"use",
"(",
"$",
"attributeName",
",",
"$",
"unindexablePredicates",
")",
"{",
"if",
"(",
"$",
"part",
"instanceof",
"self",
")",
"{",
"return",
"$",
"part",
"->",
"getAttributeConditions",
"(",
"$",
"attributeName",
",",
"$",
"unindexablePredicates",
")",
";",
"}",
"return",
"!",
"$",
"unindexablePredicates",
"&&",
"in_array",
"(",
"$",
"attributeName",
",",
"$",
"part",
"->",
"getAttributes",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] | Return all conditions of the specified type in this expression which use
the indicated attribute as an operand.
@param string $attributeName
@param bool $unindexablePredicates Whether to return only indexable predicates
(using AND) or only unindexable predicates
(using OR or NOT)
@return Condition[] | [
"Return",
"all",
"conditions",
"of",
"the",
"specified",
"type",
"in",
"this",
"expression",
"which",
"use",
"the",
"indicated",
"attribute",
"as",
"an",
"operand",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Expression/Condition/Logical/Logical.php#L43-L55 | train |
ScaraMVC/Framework | src/Scara/Foundation/Application.php | Application.boot | public function boot()
{
$this->loadConfig();
$this->registerExceptionHandler();
$this->registerProviders();
$this->registerAliases();
$this->registerScaraMasterSessionToken();
} | php | public function boot()
{
$this->loadConfig();
$this->registerExceptionHandler();
$this->registerProviders();
$this->registerAliases();
$this->registerScaraMasterSessionToken();
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"$",
"this",
"->",
"loadConfig",
"(",
")",
";",
"$",
"this",
"->",
"registerExceptionHandler",
"(",
")",
";",
"$",
"this",
"->",
"registerProviders",
"(",
")",
";",
"$",
"this",
"->",
"registerAliases",
"(",
")",
";",
"$",
"this",
"->",
"registerScaraMasterSessionToken",
"(",
")",
";",
"}"
] | Handles registering Scara's pre-execution status.
@return void | [
"Handles",
"registering",
"Scara",
"s",
"pre",
"-",
"execution",
"status",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Foundation/Application.php#L58-L65 | train |
ScaraMVC/Framework | src/Scara/Foundation/Application.php | Application.loadConfig | private function loadConfig()
{
$this->_config = new Configuration();
$this->_config->from('app');
// let's go ahead and set timezone
date_default_timezone_set($this->_config->get('timezone'));
} | php | private function loadConfig()
{
$this->_config = new Configuration();
$this->_config->from('app');
// let's go ahead and set timezone
date_default_timezone_set($this->_config->get('timezone'));
} | [
"private",
"function",
"loadConfig",
"(",
")",
"{",
"$",
"this",
"->",
"_config",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"this",
"->",
"_config",
"->",
"from",
"(",
"'app'",
")",
";",
"// let's go ahead and set timezone",
"date_default_timezone_set",
"(",
"$",
"this",
"->",
"_config",
"->",
"get",
"(",
"'timezone'",
")",
")",
";",
"}"
] | Loads the application's main configuration.
@return void | [
"Loads",
"the",
"application",
"s",
"main",
"configuration",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Foundation/Application.php#L84-L91 | train |
ScaraMVC/Framework | src/Scara/Foundation/Application.php | Application.registerControllers | private function registerControllers()
{
$this->_controller = new Controller();
$this->_controller->load($this->_router,
$this->_config->get('basepath'));
} | php | private function registerControllers()
{
$this->_controller = new Controller();
$this->_controller->load($this->_router,
$this->_config->get('basepath'));
} | [
"private",
"function",
"registerControllers",
"(",
")",
"{",
"$",
"this",
"->",
"_controller",
"=",
"new",
"Controller",
"(",
")",
";",
"$",
"this",
"->",
"_controller",
"->",
"load",
"(",
"$",
"this",
"->",
"_router",
",",
"$",
"this",
"->",
"_config",
"->",
"get",
"(",
"'basepath'",
")",
")",
";",
"}"
] | Responsible for registering the app controllers.
@return void | [
"Responsible",
"for",
"registering",
"the",
"app",
"controllers",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Foundation/Application.php#L143-L148 | train |
ScaraMVC/Framework | src/Scara/Foundation/Application.php | Application.registerScaraMasterSessionToken | private function registerScaraMasterSessionToken()
{
$s = SessionInitializer::init();
$h = new OpenSslHasher();
if (!$s->has('SCARA_SESSION_TOKEN')) {
$token = substr($h->tokenize($h->random_string(16), time()), 0, 16);
$session = $h->tokenize($token, hash('sha256', $_SERVER['HTTP_USER_AGENT']));
$s->set('SCARA_SESSION_TOKEN', $token);
$s->set('SCARA_SESSION', $session);
}
} | php | private function registerScaraMasterSessionToken()
{
$s = SessionInitializer::init();
$h = new OpenSslHasher();
if (!$s->has('SCARA_SESSION_TOKEN')) {
$token = substr($h->tokenize($h->random_string(16), time()), 0, 16);
$session = $h->tokenize($token, hash('sha256', $_SERVER['HTTP_USER_AGENT']));
$s->set('SCARA_SESSION_TOKEN', $token);
$s->set('SCARA_SESSION', $session);
}
} | [
"private",
"function",
"registerScaraMasterSessionToken",
"(",
")",
"{",
"$",
"s",
"=",
"SessionInitializer",
"::",
"init",
"(",
")",
";",
"$",
"h",
"=",
"new",
"OpenSslHasher",
"(",
")",
";",
"if",
"(",
"!",
"$",
"s",
"->",
"has",
"(",
"'SCARA_SESSION_TOKEN'",
")",
")",
"{",
"$",
"token",
"=",
"substr",
"(",
"$",
"h",
"->",
"tokenize",
"(",
"$",
"h",
"->",
"random_string",
"(",
"16",
")",
",",
"time",
"(",
")",
")",
",",
"0",
",",
"16",
")",
";",
"$",
"session",
"=",
"$",
"h",
"->",
"tokenize",
"(",
"$",
"token",
",",
"hash",
"(",
"'sha256'",
",",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
")",
";",
"$",
"s",
"->",
"set",
"(",
"'SCARA_SESSION_TOKEN'",
",",
"$",
"token",
")",
";",
"$",
"s",
"->",
"set",
"(",
"'SCARA_SESSION'",
",",
"$",
"session",
")",
";",
"}",
"}"
] | Registers Scara's master session.
@return void | [
"Registers",
"Scara",
"s",
"master",
"session",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Foundation/Application.php#L155-L166 | train |
infusephp/cron | src/Libs/Runner.php | Runner.setUp | private function setUp($class, Run $run)
{
if (!$class) {
$run->writeOutput("Missing `class` parameter on {$this->jobModel->id} job")
->setResult(Run::RESULT_FAILED);
return false;
}
if (!class_exists($class)) {
$run->writeOutput("$class does not exist")
->setResult(Run::RESULT_FAILED);
return false;
}
$job = new $class();
// inject the DI container if needed
if (method_exists($job, 'setApp')) {
$job->setApp($this->jobModel->getApp());
}
return $job;
} | php | private function setUp($class, Run $run)
{
if (!$class) {
$run->writeOutput("Missing `class` parameter on {$this->jobModel->id} job")
->setResult(Run::RESULT_FAILED);
return false;
}
if (!class_exists($class)) {
$run->writeOutput("$class does not exist")
->setResult(Run::RESULT_FAILED);
return false;
}
$job = new $class();
// inject the DI container if needed
if (method_exists($job, 'setApp')) {
$job->setApp($this->jobModel->getApp());
}
return $job;
} | [
"private",
"function",
"setUp",
"(",
"$",
"class",
",",
"Run",
"$",
"run",
")",
"{",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"$",
"run",
"->",
"writeOutput",
"(",
"\"Missing `class` parameter on {$this->jobModel->id} job\"",
")",
"->",
"setResult",
"(",
"Run",
"::",
"RESULT_FAILED",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"run",
"->",
"writeOutput",
"(",
"\"$class does not exist\"",
")",
"->",
"setResult",
"(",
"Run",
"::",
"RESULT_FAILED",
")",
";",
"return",
"false",
";",
"}",
"$",
"job",
"=",
"new",
"$",
"class",
"(",
")",
";",
"// inject the DI container if needed",
"if",
"(",
"method_exists",
"(",
"$",
"job",
",",
"'setApp'",
")",
")",
"{",
"$",
"job",
"->",
"setApp",
"(",
"$",
"this",
"->",
"jobModel",
"->",
"getApp",
"(",
")",
")",
";",
"}",
"return",
"$",
"job",
";",
"}"
] | Sets up an invokable class for a scheduled job run.
@param string $class
@param Run $run
@return callable|false | [
"Sets",
"up",
"an",
"invokable",
"class",
"for",
"a",
"scheduled",
"job",
"run",
"."
] | 783f6078b455a48415efeba0a6ee97ab17a3a903 | https://github.com/infusephp/cron/blob/783f6078b455a48415efeba0a6ee97ab17a3a903/src/Libs/Runner.php#L135-L159 | train |
infusephp/cron | src/Libs/Runner.php | Runner.invoke | private function invoke(callable $job, Run $run)
{
try {
ob_start();
$ret = call_user_func($job, $run);
$result = Run::RESULT_SUCCEEDED;
if (false === $ret) {
$result = Run::RESULT_FAILED;
}
return $run->writeOutput(ob_get_clean())
->setResult($result);
} catch (Exception $e) {
if ($this->logger) {
$this->logger->error("An uncaught exception occurred while running the {$this->jobModel->id()} scheduled job.", ['exception' => $e]);
}
return $run->writeOutput(ob_get_clean())
->writeOutput($e->getMessage())
->setResult(Run::RESULT_FAILED);
}
} | php | private function invoke(callable $job, Run $run)
{
try {
ob_start();
$ret = call_user_func($job, $run);
$result = Run::RESULT_SUCCEEDED;
if (false === $ret) {
$result = Run::RESULT_FAILED;
}
return $run->writeOutput(ob_get_clean())
->setResult($result);
} catch (Exception $e) {
if ($this->logger) {
$this->logger->error("An uncaught exception occurred while running the {$this->jobModel->id()} scheduled job.", ['exception' => $e]);
}
return $run->writeOutput(ob_get_clean())
->writeOutput($e->getMessage())
->setResult(Run::RESULT_FAILED);
}
} | [
"private",
"function",
"invoke",
"(",
"callable",
"$",
"job",
",",
"Run",
"$",
"run",
")",
"{",
"try",
"{",
"ob_start",
"(",
")",
";",
"$",
"ret",
"=",
"call_user_func",
"(",
"$",
"job",
",",
"$",
"run",
")",
";",
"$",
"result",
"=",
"Run",
"::",
"RESULT_SUCCEEDED",
";",
"if",
"(",
"false",
"===",
"$",
"ret",
")",
"{",
"$",
"result",
"=",
"Run",
"::",
"RESULT_FAILED",
";",
"}",
"return",
"$",
"run",
"->",
"writeOutput",
"(",
"ob_get_clean",
"(",
")",
")",
"->",
"setResult",
"(",
"$",
"result",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"\"An uncaught exception occurred while running the {$this->jobModel->id()} scheduled job.\"",
",",
"[",
"'exception'",
"=>",
"$",
"e",
"]",
")",
";",
"}",
"return",
"$",
"run",
"->",
"writeOutput",
"(",
"ob_get_clean",
"(",
")",
")",
"->",
"writeOutput",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
"->",
"setResult",
"(",
"Run",
"::",
"RESULT_FAILED",
")",
";",
"}",
"}"
] | Executes the actual job.
@param Run $run
@return Run | [
"Executes",
"the",
"actual",
"job",
"."
] | 783f6078b455a48415efeba0a6ee97ab17a3a903 | https://github.com/infusephp/cron/blob/783f6078b455a48415efeba0a6ee97ab17a3a903/src/Libs/Runner.php#L168-L190 | train |
infusephp/cron | src/Libs/Runner.php | Runner.saveRun | private function saveRun(Run $run)
{
$this->jobModel->last_ran = time();
$this->jobModel->last_run_succeeded = $run->succeeded();
$this->jobModel->last_run_output = $run->getOutput();
$this->jobModel->save();
} | php | private function saveRun(Run $run)
{
$this->jobModel->last_ran = time();
$this->jobModel->last_run_succeeded = $run->succeeded();
$this->jobModel->last_run_output = $run->getOutput();
$this->jobModel->save();
} | [
"private",
"function",
"saveRun",
"(",
"Run",
"$",
"run",
")",
"{",
"$",
"this",
"->",
"jobModel",
"->",
"last_ran",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"jobModel",
"->",
"last_run_succeeded",
"=",
"$",
"run",
"->",
"succeeded",
"(",
")",
";",
"$",
"this",
"->",
"jobModel",
"->",
"last_run_output",
"=",
"$",
"run",
"->",
"getOutput",
"(",
")",
";",
"$",
"this",
"->",
"jobModel",
"->",
"save",
"(",
")",
";",
"}"
] | Saves the run attempt.
@param Run $run | [
"Saves",
"the",
"run",
"attempt",
"."
] | 783f6078b455a48415efeba0a6ee97ab17a3a903 | https://github.com/infusephp/cron/blob/783f6078b455a48415efeba0a6ee97ab17a3a903/src/Libs/Runner.php#L197-L203 | train |
pdyn/base | ErrorHandler.php | ErrorHandler.format_backtrace | public static function format_backtrace($backtrace) {
global $CFG;
$html = '';
$i = count($backtrace);
foreach ($backtrace as $trace) {
$file = (isset($trace['file'])) ? str_replace($CFG->base_absroot, '', $trace['file']) : 'unknown';
$line = 'Line: '. ((isset($trace['line'])) ? $trace['line'] : '-');
$func = ((isset($trace['function'])) ? $trace['function'] : '');
ini_set('html_errors', 0);
$argstr = [];
if (!empty($trace['args']) && is_array($trace['args'])) {
foreach ($trace['args'] as $arg) {
ob_start();
var_dump($arg);
$stringval = ob_get_contents();
ob_end_clean();
$argstr[] = $stringval;
}
}
$args = implode(', ', $argstr);
$func .= '('.$args.')';
if (\pdyn\base\Utils::is_cli_env() === true) {
$html .= $i."\t".$file."\t".$line."\t".$func."\n";
} else {
$html .= '<tr>';
$html .= '<td style="vertical-align:top">'.$i.'</td>';
$html .= '<td style="vertical-align:top">'.$file.'</td>';
$html .= '<td style="vertical-align:top">'.$line.'</td>';
$html .= '<td><pre style="margin:0;">'.$func.'</pre></td>';
$html .= '</tr>';
}
$i--;
}
return (\pdyn\base\Utils::is_cli_env() === true)
? "**********\n".$html."**********\n"
: '<table cellspacing="5" style="color:inherit">'.$html.'</table>';
} | php | public static function format_backtrace($backtrace) {
global $CFG;
$html = '';
$i = count($backtrace);
foreach ($backtrace as $trace) {
$file = (isset($trace['file'])) ? str_replace($CFG->base_absroot, '', $trace['file']) : 'unknown';
$line = 'Line: '. ((isset($trace['line'])) ? $trace['line'] : '-');
$func = ((isset($trace['function'])) ? $trace['function'] : '');
ini_set('html_errors', 0);
$argstr = [];
if (!empty($trace['args']) && is_array($trace['args'])) {
foreach ($trace['args'] as $arg) {
ob_start();
var_dump($arg);
$stringval = ob_get_contents();
ob_end_clean();
$argstr[] = $stringval;
}
}
$args = implode(', ', $argstr);
$func .= '('.$args.')';
if (\pdyn\base\Utils::is_cli_env() === true) {
$html .= $i."\t".$file."\t".$line."\t".$func."\n";
} else {
$html .= '<tr>';
$html .= '<td style="vertical-align:top">'.$i.'</td>';
$html .= '<td style="vertical-align:top">'.$file.'</td>';
$html .= '<td style="vertical-align:top">'.$line.'</td>';
$html .= '<td><pre style="margin:0;">'.$func.'</pre></td>';
$html .= '</tr>';
}
$i--;
}
return (\pdyn\base\Utils::is_cli_env() === true)
? "**********\n".$html."**********\n"
: '<table cellspacing="5" style="color:inherit">'.$html.'</table>';
} | [
"public",
"static",
"function",
"format_backtrace",
"(",
"$",
"backtrace",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"html",
"=",
"''",
";",
"$",
"i",
"=",
"count",
"(",
"$",
"backtrace",
")",
";",
"foreach",
"(",
"$",
"backtrace",
"as",
"$",
"trace",
")",
"{",
"$",
"file",
"=",
"(",
"isset",
"(",
"$",
"trace",
"[",
"'file'",
"]",
")",
")",
"?",
"str_replace",
"(",
"$",
"CFG",
"->",
"base_absroot",
",",
"''",
",",
"$",
"trace",
"[",
"'file'",
"]",
")",
":",
"'unknown'",
";",
"$",
"line",
"=",
"'Line: '",
".",
"(",
"(",
"isset",
"(",
"$",
"trace",
"[",
"'line'",
"]",
")",
")",
"?",
"$",
"trace",
"[",
"'line'",
"]",
":",
"'-'",
")",
";",
"$",
"func",
"=",
"(",
"(",
"isset",
"(",
"$",
"trace",
"[",
"'function'",
"]",
")",
")",
"?",
"$",
"trace",
"[",
"'function'",
"]",
":",
"''",
")",
";",
"ini_set",
"(",
"'html_errors'",
",",
"0",
")",
";",
"$",
"argstr",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"trace",
"[",
"'args'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"trace",
"[",
"'args'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"trace",
"[",
"'args'",
"]",
"as",
"$",
"arg",
")",
"{",
"ob_start",
"(",
")",
";",
"var_dump",
"(",
"$",
"arg",
")",
";",
"$",
"stringval",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"$",
"argstr",
"[",
"]",
"=",
"$",
"stringval",
";",
"}",
"}",
"$",
"args",
"=",
"implode",
"(",
"', '",
",",
"$",
"argstr",
")",
";",
"$",
"func",
".=",
"'('",
".",
"$",
"args",
".",
"')'",
";",
"if",
"(",
"\\",
"pdyn",
"\\",
"base",
"\\",
"Utils",
"::",
"is_cli_env",
"(",
")",
"===",
"true",
")",
"{",
"$",
"html",
".=",
"$",
"i",
".",
"\"\\t\"",
".",
"$",
"file",
".",
"\"\\t\"",
".",
"$",
"line",
".",
"\"\\t\"",
".",
"$",
"func",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"$",
"html",
".=",
"'<tr>'",
";",
"$",
"html",
".=",
"'<td style=\"vertical-align:top\">'",
".",
"$",
"i",
".",
"'</td>'",
";",
"$",
"html",
".=",
"'<td style=\"vertical-align:top\">'",
".",
"$",
"file",
".",
"'</td>'",
";",
"$",
"html",
".=",
"'<td style=\"vertical-align:top\">'",
".",
"$",
"line",
".",
"'</td>'",
";",
"$",
"html",
".=",
"'<td><pre style=\"margin:0;\">'",
".",
"$",
"func",
".",
"'</pre></td>'",
";",
"$",
"html",
".=",
"'</tr>'",
";",
"}",
"$",
"i",
"--",
";",
"}",
"return",
"(",
"\\",
"pdyn",
"\\",
"base",
"\\",
"Utils",
"::",
"is_cli_env",
"(",
")",
"===",
"true",
")",
"?",
"\"**********\\n\"",
".",
"$",
"html",
".",
"\"**********\\n\"",
":",
"'<table cellspacing=\"5\" style=\"color:inherit\">'",
".",
"$",
"html",
".",
"'</table>'",
";",
"}"
] | Format a backtrace for better display.
@param array $backtrace A backtrace from debug_backtrace.
@return string Html that better displays the backtrace. | [
"Format",
"a",
"backtrace",
"for",
"better",
"display",
"."
] | 0b93961693954a6b4e1c6df7e345e5cdf07f26ff | https://github.com/pdyn/base/blob/0b93961693954a6b4e1c6df7e345e5cdf07f26ff/ErrorHandler.php#L93-L129 | train |
pdyn/base | ErrorHandler.php | ErrorHandler.error_handler | public static function error_handler($errcode, $errstr, $errfile, $errline, $errcontext) {
throw new \Exception($errstr.' in '.$errfile.' on line '.$errline, $errcode);
} | php | public static function error_handler($errcode, $errstr, $errfile, $errline, $errcontext) {
throw new \Exception($errstr.' in '.$errfile.' on line '.$errline, $errcode);
} | [
"public",
"static",
"function",
"error_handler",
"(",
"$",
"errcode",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
",",
"$",
"errcontext",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"errstr",
".",
"' in '",
".",
"$",
"errfile",
".",
"' on line '",
".",
"$",
"errline",
",",
"$",
"errcode",
")",
";",
"}"
] | Handle PHP errors.
@param int $errcode The error code.
@param string $errstr The error description
@param string $errfile The file the error occurred in.
@param int $errline The line the error occurred on. | [
"Handle",
"PHP",
"errors",
"."
] | 0b93961693954a6b4e1c6df7e345e5cdf07f26ff | https://github.com/pdyn/base/blob/0b93961693954a6b4e1c6df7e345e5cdf07f26ff/ErrorHandler.php#L139-L141 | train |
pdyn/base | ErrorHandler.php | ErrorHandler.write_error_html | public static function write_error_html($errtitle, $errdetails, $errcode, $backtrace = null) {
global $USR;
?>
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title><?php echo $errtitle ?></title>
<style>
html {
background-color: #111;
font-family: sans-serif;
color: #fff;
}
.errbox {
margin: 3rem;
padding: 1rem;
border-radius: 0.5rem;
background-color: #500;
border: 1px solid #f00;
}
.errbox h1, .errbox h2, .errbox h4 {
margin: 0;
padding: 0;
}
.errbox h1 {
text-align: center;
margin: 1rem 1rem 2rem;
}
.errbox h4 {
margin-bottom: 1rem;
}
.errbox > div {
background-color: #300;
border: 1px solid #800;
padding: 1rem;
}
</style>
</head>
<body>
<div id="page">
<div id="subContent">
<div class="errbox">
<?php
echo '<h1>'.$errcode.': '.$errtitle.'</h1>';
if (!empty($errdetails)) {
echo '<div><h2>'.$errdetails.'</h2></div>';
}
if (!empty($USR) && $USR->is_admin === true && !empty($backtrace)) {
echo '<div><h4>Backtrace:</h4>'.$backtrace.'</div>';
}
?>
</div>
</div>
</div>
</body>
</html>
<?php
} | php | public static function write_error_html($errtitle, $errdetails, $errcode, $backtrace = null) {
global $USR;
?>
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title><?php echo $errtitle ?></title>
<style>
html {
background-color: #111;
font-family: sans-serif;
color: #fff;
}
.errbox {
margin: 3rem;
padding: 1rem;
border-radius: 0.5rem;
background-color: #500;
border: 1px solid #f00;
}
.errbox h1, .errbox h2, .errbox h4 {
margin: 0;
padding: 0;
}
.errbox h1 {
text-align: center;
margin: 1rem 1rem 2rem;
}
.errbox h4 {
margin-bottom: 1rem;
}
.errbox > div {
background-color: #300;
border: 1px solid #800;
padding: 1rem;
}
</style>
</head>
<body>
<div id="page">
<div id="subContent">
<div class="errbox">
<?php
echo '<h1>'.$errcode.': '.$errtitle.'</h1>';
if (!empty($errdetails)) {
echo '<div><h2>'.$errdetails.'</h2></div>';
}
if (!empty($USR) && $USR->is_admin === true && !empty($backtrace)) {
echo '<div><h4>Backtrace:</h4>'.$backtrace.'</div>';
}
?>
</div>
</div>
</div>
</body>
</html>
<?php
} | [
"public",
"static",
"function",
"write_error_html",
"(",
"$",
"errtitle",
",",
"$",
"errdetails",
",",
"$",
"errcode",
",",
"$",
"backtrace",
"=",
"null",
")",
"{",
"global",
"$",
"USR",
";",
"?>\n\t\t<!DOCTYPE HTML>\n\t\t<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\">\n\t\t\t<head>\n\t\t\t\t<meta charset=\"UTF-8\" />\n\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n\t\t\t\t<title><?php",
"echo",
"$",
"errtitle",
"?></title>\n\t\t\t\t<style>\n\t\t\t\t\thtml {\n\t\t\t\t\t\tbackground-color: #111;\n\t\t\t\t\t\tfont-family: sans-serif;\n\t\t\t\t\t\tcolor: #fff;\n\t\t\t\t\t}\n\t\t\t\t\t.errbox {\n\t\t\t\t\t\tmargin: 3rem;\n\t\t\t\t\t\tpadding: 1rem;\n\t\t\t\t\t\tborder-radius: 0.5rem;\n\t\t\t\t\t\tbackground-color: #500;\n\t\t\t\t\t\tborder: 1px solid #f00;\n\t\t\t\t\t}\n\t\t\t\t\t.errbox h1, .errbox h2, .errbox h4 {\n\t\t\t\t\t\tmargin: 0;\n\t\t\t\t\t\tpadding: 0;\n\t\t\t\t\t}\n\t\t\t\t\t.errbox h1 {\n\t\t\t\t\t\ttext-align: center;\n\t\t\t\t\t\tmargin: 1rem 1rem 2rem;\n\t\t\t\t\t}\n\t\t\t\t\t.errbox h4 {\n\t\t\t\t\t\tmargin-bottom: 1rem;\n\t\t\t\t\t}\n\t\t\t\t\t.errbox > div {\n\t\t\t\t\t\tbackground-color: #300;\n\t\t\t\t\t\tborder: 1px solid #800;\n\t\t\t\t\t\tpadding: 1rem;\n\t\t\t\t\t}\n\t\t\t\t</style>\n\t\t\t</head>\n\t\t\t<body>\n\t\t\t\t<div id=\"page\">\n\t\t\t\t\t<div id=\"subContent\">\n\t\t\t\t\t\t<div class=\"errbox\">\n\t\t\t\t\t\t\t<?php",
"echo",
"'<h1>'",
".",
"$",
"errcode",
".",
"': '",
".",
"$",
"errtitle",
".",
"'</h1>'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"errdetails",
")",
")",
"{",
"echo",
"'<div><h2>'",
".",
"$",
"errdetails",
".",
"'</h2></div>'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"USR",
")",
"&&",
"$",
"USR",
"->",
"is_admin",
"===",
"true",
"&&",
"!",
"empty",
"(",
"$",
"backtrace",
")",
")",
"{",
"echo",
"'<div><h4>Backtrace:</h4>'",
".",
"$",
"backtrace",
".",
"'</div>'",
";",
"}",
"?>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</body>\n\t\t</html>\n\t\t<?php",
"}"
] | For handle-able errors, print out our custom error screen.
@param string $errtitle The title of the error.
@param string $errdetails Details of the error.
@param string $errcode (Optional) An error code.
@param string $backtrace (Optional) A backtrace. | [
"For",
"handle",
"-",
"able",
"errors",
"print",
"out",
"our",
"custom",
"error",
"screen",
"."
] | 0b93961693954a6b4e1c6df7e345e5cdf07f26ff | https://github.com/pdyn/base/blob/0b93961693954a6b4e1c6df7e345e5cdf07f26ff/ErrorHandler.php#L151-L210 | train |
mrofi/video-info | src/DailyMotion.php | DailyMotion.getDailyMotionId | public function getDailyMotionId($url)
{
if (preg_match('!^.+dailymotion\.com/(video|hub)/([^_]+)[^#]*(#video=([^_&]+))?|(dai\.ly/([^_]+))!', $url, $m)) {
if (isset($m[6])) {
return $m[6];
}
if (isset($m[4])) {
return $m[4];
}
return $m[2];
}
return false;
} | php | public function getDailyMotionId($url)
{
if (preg_match('!^.+dailymotion\.com/(video|hub)/([^_]+)[^#]*(#video=([^_&]+))?|(dai\.ly/([^_]+))!', $url, $m)) {
if (isset($m[6])) {
return $m[6];
}
if (isset($m[4])) {
return $m[4];
}
return $m[2];
}
return false;
} | [
"public",
"function",
"getDailyMotionId",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'!^.+dailymotion\\.com/(video|hub)/([^_]+)[^#]*(#video=([^_&]+))?|(dai\\.ly/([^_]+))!'",
",",
"$",
"url",
",",
"$",
"m",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"m",
"[",
"6",
"]",
")",
")",
"{",
"return",
"$",
"m",
"[",
"6",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"m",
"[",
"4",
"]",
")",
")",
"{",
"return",
"$",
"m",
"[",
"4",
"]",
";",
"}",
"return",
"$",
"m",
"[",
"2",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Extracts the daily motion id from a daily motion url.
Returns false if the url is not recognized as a daily motion url. | [
"Extracts",
"the",
"daily",
"motion",
"id",
"from",
"a",
"daily",
"motion",
"url",
".",
"Returns",
"false",
"if",
"the",
"url",
"is",
"not",
"recognized",
"as",
"a",
"daily",
"motion",
"url",
"."
] | fa5b84212d04c284bb289a18c33c660881c92863 | https://github.com/mrofi/video-info/blob/fa5b84212d04c284bb289a18c33c660881c92863/src/DailyMotion.php#L40-L52 | train |
KDF5000/EasyThink | src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_debug.php | Smarty_Internal_Debug.display_debug | public static function display_debug($obj)
{
// prepare information of assigned variables
$ptr = self::get_debug_vars($obj);
if ($obj instanceof Smarty) {
$smarty = clone $obj;
} else {
$smarty = clone $obj->smarty;
}
$_assigned_vars = $ptr->tpl_vars;
ksort($_assigned_vars);
$_config_vars = $ptr->config_vars;
ksort($_config_vars);
$smarty->registered_filters = array();
$smarty->autoload_filters = array();
$smarty->default_modifiers = array();
$smarty->force_compile = false;
$smarty->left_delimiter = '{';
$smarty->right_delimiter = '}';
$smarty->debugging = false;
$smarty->force_compile = false;
$_template = new Smarty_Internal_Template($smarty->debug_tpl, $smarty);
$_template->caching = false;
$_template->disableSecurity();
$_template->cache_id = null;
$_template->compile_id = null;
if ($obj instanceof Smarty_Internal_Template) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
}
if ($obj instanceof Smarty) {
$_template->assign('template_data', self::$template_data);
} else {
$_template->assign('template_data', null);
}
$_template->assign('assigned_vars', $_assigned_vars);
$_template->assign('config_vars', $_config_vars);
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
echo $_template->fetch();
} | php | public static function display_debug($obj)
{
// prepare information of assigned variables
$ptr = self::get_debug_vars($obj);
if ($obj instanceof Smarty) {
$smarty = clone $obj;
} else {
$smarty = clone $obj->smarty;
}
$_assigned_vars = $ptr->tpl_vars;
ksort($_assigned_vars);
$_config_vars = $ptr->config_vars;
ksort($_config_vars);
$smarty->registered_filters = array();
$smarty->autoload_filters = array();
$smarty->default_modifiers = array();
$smarty->force_compile = false;
$smarty->left_delimiter = '{';
$smarty->right_delimiter = '}';
$smarty->debugging = false;
$smarty->force_compile = false;
$_template = new Smarty_Internal_Template($smarty->debug_tpl, $smarty);
$_template->caching = false;
$_template->disableSecurity();
$_template->cache_id = null;
$_template->compile_id = null;
if ($obj instanceof Smarty_Internal_Template) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
}
if ($obj instanceof Smarty) {
$_template->assign('template_data', self::$template_data);
} else {
$_template->assign('template_data', null);
}
$_template->assign('assigned_vars', $_assigned_vars);
$_template->assign('config_vars', $_config_vars);
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
echo $_template->fetch();
} | [
"public",
"static",
"function",
"display_debug",
"(",
"$",
"obj",
")",
"{",
"// prepare information of assigned variables",
"$",
"ptr",
"=",
"self",
"::",
"get_debug_vars",
"(",
"$",
"obj",
")",
";",
"if",
"(",
"$",
"obj",
"instanceof",
"Smarty",
")",
"{",
"$",
"smarty",
"=",
"clone",
"$",
"obj",
";",
"}",
"else",
"{",
"$",
"smarty",
"=",
"clone",
"$",
"obj",
"->",
"smarty",
";",
"}",
"$",
"_assigned_vars",
"=",
"$",
"ptr",
"->",
"tpl_vars",
";",
"ksort",
"(",
"$",
"_assigned_vars",
")",
";",
"$",
"_config_vars",
"=",
"$",
"ptr",
"->",
"config_vars",
";",
"ksort",
"(",
"$",
"_config_vars",
")",
";",
"$",
"smarty",
"->",
"registered_filters",
"=",
"array",
"(",
")",
";",
"$",
"smarty",
"->",
"autoload_filters",
"=",
"array",
"(",
")",
";",
"$",
"smarty",
"->",
"default_modifiers",
"=",
"array",
"(",
")",
";",
"$",
"smarty",
"->",
"force_compile",
"=",
"false",
";",
"$",
"smarty",
"->",
"left_delimiter",
"=",
"'{'",
";",
"$",
"smarty",
"->",
"right_delimiter",
"=",
"'}'",
";",
"$",
"smarty",
"->",
"debugging",
"=",
"false",
";",
"$",
"smarty",
"->",
"force_compile",
"=",
"false",
";",
"$",
"_template",
"=",
"new",
"Smarty_Internal_Template",
"(",
"$",
"smarty",
"->",
"debug_tpl",
",",
"$",
"smarty",
")",
";",
"$",
"_template",
"->",
"caching",
"=",
"false",
";",
"$",
"_template",
"->",
"disableSecurity",
"(",
")",
";",
"$",
"_template",
"->",
"cache_id",
"=",
"null",
";",
"$",
"_template",
"->",
"compile_id",
"=",
"null",
";",
"if",
"(",
"$",
"obj",
"instanceof",
"Smarty_Internal_Template",
")",
"{",
"$",
"_template",
"->",
"assign",
"(",
"'template_name'",
",",
"$",
"obj",
"->",
"source",
"->",
"type",
".",
"':'",
".",
"$",
"obj",
"->",
"source",
"->",
"name",
")",
";",
"}",
"if",
"(",
"$",
"obj",
"instanceof",
"Smarty",
")",
"{",
"$",
"_template",
"->",
"assign",
"(",
"'template_data'",
",",
"self",
"::",
"$",
"template_data",
")",
";",
"}",
"else",
"{",
"$",
"_template",
"->",
"assign",
"(",
"'template_data'",
",",
"null",
")",
";",
"}",
"$",
"_template",
"->",
"assign",
"(",
"'assigned_vars'",
",",
"$",
"_assigned_vars",
")",
";",
"$",
"_template",
"->",
"assign",
"(",
"'config_vars'",
",",
"$",
"_config_vars",
")",
";",
"$",
"_template",
"->",
"assign",
"(",
"'execution_time'",
",",
"microtime",
"(",
"true",
")",
"-",
"$",
"smarty",
"->",
"start_time",
")",
";",
"echo",
"$",
"_template",
"->",
"fetch",
"(",
")",
";",
"}"
] | Opens a window for the Smarty Debugging Consol and display the data
@param Smarty_Internal_Template|Smarty $obj object to debug | [
"Opens",
"a",
"window",
"for",
"the",
"Smarty",
"Debugging",
"Consol",
"and",
"display",
"the",
"data"
] | 86efc9c8a0d504e01e2fea55868227fdc8928841 | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_debug.php#L98-L136 | train |
juliangut/mapping | src/Driver/AbstractDriverFactory.php | AbstractDriverFactory.getDriver | public function getDriver(array $mappingSource): DriverInterface
{
if (\array_key_exists('driver', $mappingSource)) {
$driver = $mappingSource['driver'];
if (!$driver instanceof DriverInterface) {
throw new DriverException(\sprintf(
'Metadata mapping driver should be of the type %s, %s given',
DriverInterface::class,
\is_object($driver) ? \get_class($driver) : \gettype($driver)
));
}
return $driver;
}
$supportedKeys = ['type', 'path'];
if (\count(\array_intersect($supportedKeys, \array_keys($mappingSource))) === \count($supportedKeys)) {
return $this->getDriverImplementation($mappingSource['type'], (array) $mappingSource['path']);
}
throw new DriverException(
'Mapping must be array with "driver" key or "type" and "path" keys'
);
} | php | public function getDriver(array $mappingSource): DriverInterface
{
if (\array_key_exists('driver', $mappingSource)) {
$driver = $mappingSource['driver'];
if (!$driver instanceof DriverInterface) {
throw new DriverException(\sprintf(
'Metadata mapping driver should be of the type %s, %s given',
DriverInterface::class,
\is_object($driver) ? \get_class($driver) : \gettype($driver)
));
}
return $driver;
}
$supportedKeys = ['type', 'path'];
if (\count(\array_intersect($supportedKeys, \array_keys($mappingSource))) === \count($supportedKeys)) {
return $this->getDriverImplementation($mappingSource['type'], (array) $mappingSource['path']);
}
throw new DriverException(
'Mapping must be array with "driver" key or "type" and "path" keys'
);
} | [
"public",
"function",
"getDriver",
"(",
"array",
"$",
"mappingSource",
")",
":",
"DriverInterface",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"'driver'",
",",
"$",
"mappingSource",
")",
")",
"{",
"$",
"driver",
"=",
"$",
"mappingSource",
"[",
"'driver'",
"]",
";",
"if",
"(",
"!",
"$",
"driver",
"instanceof",
"DriverInterface",
")",
"{",
"throw",
"new",
"DriverException",
"(",
"\\",
"sprintf",
"(",
"'Metadata mapping driver should be of the type %s, %s given'",
",",
"DriverInterface",
"::",
"class",
",",
"\\",
"is_object",
"(",
"$",
"driver",
")",
"?",
"\\",
"get_class",
"(",
"$",
"driver",
")",
":",
"\\",
"gettype",
"(",
"$",
"driver",
")",
")",
")",
";",
"}",
"return",
"$",
"driver",
";",
"}",
"$",
"supportedKeys",
"=",
"[",
"'type'",
",",
"'path'",
"]",
";",
"if",
"(",
"\\",
"count",
"(",
"\\",
"array_intersect",
"(",
"$",
"supportedKeys",
",",
"\\",
"array_keys",
"(",
"$",
"mappingSource",
")",
")",
")",
"===",
"\\",
"count",
"(",
"$",
"supportedKeys",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getDriverImplementation",
"(",
"$",
"mappingSource",
"[",
"'type'",
"]",
",",
"(",
"array",
")",
"$",
"mappingSource",
"[",
"'path'",
"]",
")",
";",
"}",
"throw",
"new",
"DriverException",
"(",
"'Mapping must be array with \"driver\" key or \"type\" and \"path\" keys'",
")",
";",
"}"
] | Get mapping driver.
@param array $mappingSource
@throws DriverException
@return DriverInterface | [
"Get",
"mapping",
"driver",
"."
] | 1830ff84c054d8e3759df170a5664a97f7070be9 | https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/AbstractDriverFactory.php#L32-L56 | train |
juliangut/mapping | src/Driver/AbstractDriverFactory.php | AbstractDriverFactory.getDriverImplementation | protected function getDriverImplementation(string $type, array $paths): DriverInterface
{
switch ($type) {
case DriverFactoryInterface::DRIVER_ANNOTATION:
return $this->getAnnotationDriver($paths);
case DriverFactoryInterface::DRIVER_PHP:
return $this->getPhpDriver($paths);
case DriverFactoryInterface::DRIVER_XML:
return $this->getXmlDriver($paths);
case DriverFactoryInterface::DRIVER_JSON:
return $this->getJsonDriver($paths);
case DriverFactoryInterface::DRIVER_YAML:
return $this->getYamlDriver($paths);
}
throw new DriverException(
\sprintf('"%s" is not a valid metadata mapping driver', $type)
);
} | php | protected function getDriverImplementation(string $type, array $paths): DriverInterface
{
switch ($type) {
case DriverFactoryInterface::DRIVER_ANNOTATION:
return $this->getAnnotationDriver($paths);
case DriverFactoryInterface::DRIVER_PHP:
return $this->getPhpDriver($paths);
case DriverFactoryInterface::DRIVER_XML:
return $this->getXmlDriver($paths);
case DriverFactoryInterface::DRIVER_JSON:
return $this->getJsonDriver($paths);
case DriverFactoryInterface::DRIVER_YAML:
return $this->getYamlDriver($paths);
}
throw new DriverException(
\sprintf('"%s" is not a valid metadata mapping driver', $type)
);
} | [
"protected",
"function",
"getDriverImplementation",
"(",
"string",
"$",
"type",
",",
"array",
"$",
"paths",
")",
":",
"DriverInterface",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"DriverFactoryInterface",
"::",
"DRIVER_ANNOTATION",
":",
"return",
"$",
"this",
"->",
"getAnnotationDriver",
"(",
"$",
"paths",
")",
";",
"case",
"DriverFactoryInterface",
"::",
"DRIVER_PHP",
":",
"return",
"$",
"this",
"->",
"getPhpDriver",
"(",
"$",
"paths",
")",
";",
"case",
"DriverFactoryInterface",
"::",
"DRIVER_XML",
":",
"return",
"$",
"this",
"->",
"getXmlDriver",
"(",
"$",
"paths",
")",
";",
"case",
"DriverFactoryInterface",
"::",
"DRIVER_JSON",
":",
"return",
"$",
"this",
"->",
"getJsonDriver",
"(",
"$",
"paths",
")",
";",
"case",
"DriverFactoryInterface",
"::",
"DRIVER_YAML",
":",
"return",
"$",
"this",
"->",
"getYamlDriver",
"(",
"$",
"paths",
")",
";",
"}",
"throw",
"new",
"DriverException",
"(",
"\\",
"sprintf",
"(",
"'\"%s\" is not a valid metadata mapping driver'",
",",
"$",
"type",
")",
")",
";",
"}"
] | Get mapping driver implementation.
@param string $type
@param array $paths
@throws DriverException
@return DriverInterface | [
"Get",
"mapping",
"driver",
"implementation",
"."
] | 1830ff84c054d8e3759df170a5664a97f7070be9 | https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/AbstractDriverFactory.php#L68-L90 | train |
jabernardo/lollipop-php | Library/Log.php | Log._write | private static function _write($type, $message) {
$log_path = Config::get('log.folder', LOLLIPOP_STORAGE_LOG);
$log_enable = Config::get('log.enable', true);
$log_hourly = Config::get('log.hourly', false);
if (!is_dir($log_path))
throw new \Lollipop\Exception\Runtime('Log folder doesn\'t exists');
if (!is_writeable($log_path))
throw new \Lollipop\Exception\Runtime('Log folder is not writeable');
if (!isset(self::$_messages[$type]))
throw new \Lollipop\Exception\Argument('Invalid log type');
// Save to memory
array_push(self::$_messages[$type], $message);
if ($log_enable && !self::$_busy) {
self::$_busy = true;
// Create filename base on configuration (daily or hourly)
$filename = $log_path . DIRECTORY_SEPARATOR . ($log_hourly ? date('Y-m-d-H') : date('Y-m-d')) . '.log';
// Save to file
file_put_contents($filename, date('Y-m-d H:i:s') . ' [' . strtoupper($type) . '] ' . $message . "\n", FILE_APPEND);
self::$_busy = false;
}
} | php | private static function _write($type, $message) {
$log_path = Config::get('log.folder', LOLLIPOP_STORAGE_LOG);
$log_enable = Config::get('log.enable', true);
$log_hourly = Config::get('log.hourly', false);
if (!is_dir($log_path))
throw new \Lollipop\Exception\Runtime('Log folder doesn\'t exists');
if (!is_writeable($log_path))
throw new \Lollipop\Exception\Runtime('Log folder is not writeable');
if (!isset(self::$_messages[$type]))
throw new \Lollipop\Exception\Argument('Invalid log type');
// Save to memory
array_push(self::$_messages[$type], $message);
if ($log_enable && !self::$_busy) {
self::$_busy = true;
// Create filename base on configuration (daily or hourly)
$filename = $log_path . DIRECTORY_SEPARATOR . ($log_hourly ? date('Y-m-d-H') : date('Y-m-d')) . '.log';
// Save to file
file_put_contents($filename, date('Y-m-d H:i:s') . ' [' . strtoupper($type) . '] ' . $message . "\n", FILE_APPEND);
self::$_busy = false;
}
} | [
"private",
"static",
"function",
"_write",
"(",
"$",
"type",
",",
"$",
"message",
")",
"{",
"$",
"log_path",
"=",
"Config",
"::",
"get",
"(",
"'log.folder'",
",",
"LOLLIPOP_STORAGE_LOG",
")",
";",
"$",
"log_enable",
"=",
"Config",
"::",
"get",
"(",
"'log.enable'",
",",
"true",
")",
";",
"$",
"log_hourly",
"=",
"Config",
"::",
"get",
"(",
"'log.hourly'",
",",
"false",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"log_path",
")",
")",
"throw",
"new",
"\\",
"Lollipop",
"\\",
"Exception",
"\\",
"Runtime",
"(",
"'Log folder doesn\\'t exists'",
")",
";",
"if",
"(",
"!",
"is_writeable",
"(",
"$",
"log_path",
")",
")",
"throw",
"new",
"\\",
"Lollipop",
"\\",
"Exception",
"\\",
"Runtime",
"(",
"'Log folder is not writeable'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_messages",
"[",
"$",
"type",
"]",
")",
")",
"throw",
"new",
"\\",
"Lollipop",
"\\",
"Exception",
"\\",
"Argument",
"(",
"'Invalid log type'",
")",
";",
"// Save to memory",
"array_push",
"(",
"self",
"::",
"$",
"_messages",
"[",
"$",
"type",
"]",
",",
"$",
"message",
")",
";",
"if",
"(",
"$",
"log_enable",
"&&",
"!",
"self",
"::",
"$",
"_busy",
")",
"{",
"self",
"::",
"$",
"_busy",
"=",
"true",
";",
"// Create filename base on configuration (daily or hourly)",
"$",
"filename",
"=",
"$",
"log_path",
".",
"DIRECTORY_SEPARATOR",
".",
"(",
"$",
"log_hourly",
"?",
"date",
"(",
"'Y-m-d-H'",
")",
":",
"date",
"(",
"'Y-m-d'",
")",
")",
".",
"'.log'",
";",
"// Save to file",
"file_put_contents",
"(",
"$",
"filename",
",",
"date",
"(",
"'Y-m-d H:i:s'",
")",
".",
"' ['",
".",
"strtoupper",
"(",
"$",
"type",
")",
".",
"'] '",
".",
"$",
"message",
".",
"\"\\n\"",
",",
"FILE_APPEND",
")",
";",
"self",
"::",
"$",
"_busy",
"=",
"false",
";",
"}",
"}"
] | Append to log file
@param string $message Message log
@throws \Lollipop\Exception\Runtime
@throws \Lollipop\Exception\Argument
@return bool | [
"Append",
"to",
"log",
"file"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Log.php#L53-L81 | train |
battis/data-utilities | src/DataUtilities.php | DataUtilities.loadCsvToArray | public static function loadCsvToArray($field, $firstRowLabels = true)
{
$result = false;
if (!empty($_FILES[$field]['tmp_name'])) {
/* open the file for reading */
$csv = fopen($_FILES[$field]['tmp_name'], 'r');
$result = array();
/* treat the first row as column labels */
if ($firstRowLabels) {
$fields = fgetcsv($csv);
}
/* walk through the file, storing each row in the array */
while ($csvRow = fgetcsv($csv)) {
$row = array();
/* if we have column labels, use them */
if ($firstRowLabels) {
foreach ($fields as $i => $field) {
if (isset($csvRow[$i])) {
$row[$field] = $csvRow[$i];
}
}
} else {
$row = $csvRow;
}
/* append the row to the array */
$result[] = $row;
}
fclose($csv);
}
return $result;
} | php | public static function loadCsvToArray($field, $firstRowLabels = true)
{
$result = false;
if (!empty($_FILES[$field]['tmp_name'])) {
/* open the file for reading */
$csv = fopen($_FILES[$field]['tmp_name'], 'r');
$result = array();
/* treat the first row as column labels */
if ($firstRowLabels) {
$fields = fgetcsv($csv);
}
/* walk through the file, storing each row in the array */
while ($csvRow = fgetcsv($csv)) {
$row = array();
/* if we have column labels, use them */
if ($firstRowLabels) {
foreach ($fields as $i => $field) {
if (isset($csvRow[$i])) {
$row[$field] = $csvRow[$i];
}
}
} else {
$row = $csvRow;
}
/* append the row to the array */
$result[] = $row;
}
fclose($csv);
}
return $result;
} | [
"public",
"static",
"function",
"loadCsvToArray",
"(",
"$",
"field",
",",
"$",
"firstRowLabels",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"_FILES",
"[",
"$",
"field",
"]",
"[",
"'tmp_name'",
"]",
")",
")",
"{",
"/* open the file for reading */",
"$",
"csv",
"=",
"fopen",
"(",
"$",
"_FILES",
"[",
"$",
"field",
"]",
"[",
"'tmp_name'",
"]",
",",
"'r'",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"/* treat the first row as column labels */",
"if",
"(",
"$",
"firstRowLabels",
")",
"{",
"$",
"fields",
"=",
"fgetcsv",
"(",
"$",
"csv",
")",
";",
"}",
"/* walk through the file, storing each row in the array */",
"while",
"(",
"$",
"csvRow",
"=",
"fgetcsv",
"(",
"$",
"csv",
")",
")",
"{",
"$",
"row",
"=",
"array",
"(",
")",
";",
"/* if we have column labels, use them */",
"if",
"(",
"$",
"firstRowLabels",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"i",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"csvRow",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"row",
"[",
"$",
"field",
"]",
"=",
"$",
"csvRow",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"row",
"=",
"$",
"csvRow",
";",
"}",
"/* append the row to the array */",
"$",
"result",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"fclose",
"(",
"$",
"csv",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Load an uploaded CSV file into an associative array
@param string $field Field name holding the file name
@param boolean $firstRowLabels (Optional) Default `TRUE`
@return string[][]|boolean A two-dimensional array of string values, if the
`$field` contains a CSV file, `FALSE` if there is no file | [
"Load",
"an",
"uploaded",
"CSV",
"file",
"into",
"an",
"associative",
"array"
] | 81e9771db3f3cfa1a757179ad447ee40703c55a3 | https://github.com/battis/data-utilities/blob/81e9771db3f3cfa1a757179ad447ee40703c55a3/src/DataUtilities.php#L108-L142 | train |
battis/data-utilities | src/DataUtilities.php | DataUtilities.URLfromPath | public static function URLfromPath($path, array $vars = null, $basePath = false)
{
if ($vars === null) {
if (php_sapi_name() != 'cli') {
$vars = $_SERVER;
} else {
return false;
}
}
if ($basePath !== false && substr($path, 0, 1) !== '/') {
$basePath = rtrim($basePath, '/');
$path = realpath("$basePath/$path");
}
if (realpath($path)) {
return (!isset($vars['HTTPS']) || $vars['HTTPS'] != 'on' ?
'http://' :
'https://'
) .
$vars['SERVER_NAME'] .
$vars['CONTEXT_PREFIX'] .
str_replace(
$vars['CONTEXT_DOCUMENT_ROOT'],
'',
$path
);
} else {
return false;
}
} | php | public static function URLfromPath($path, array $vars = null, $basePath = false)
{
if ($vars === null) {
if (php_sapi_name() != 'cli') {
$vars = $_SERVER;
} else {
return false;
}
}
if ($basePath !== false && substr($path, 0, 1) !== '/') {
$basePath = rtrim($basePath, '/');
$path = realpath("$basePath/$path");
}
if (realpath($path)) {
return (!isset($vars['HTTPS']) || $vars['HTTPS'] != 'on' ?
'http://' :
'https://'
) .
$vars['SERVER_NAME'] .
$vars['CONTEXT_PREFIX'] .
str_replace(
$vars['CONTEXT_DOCUMENT_ROOT'],
'',
$path
);
} else {
return false;
}
} | [
"public",
"static",
"function",
"URLfromPath",
"(",
"$",
"path",
",",
"array",
"$",
"vars",
"=",
"null",
",",
"$",
"basePath",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"vars",
"===",
"null",
")",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"!=",
"'cli'",
")",
"{",
"$",
"vars",
"=",
"$",
"_SERVER",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"basePath",
"!==",
"false",
"&&",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"basePath",
"=",
"rtrim",
"(",
"$",
"basePath",
",",
"'/'",
")",
";",
"$",
"path",
"=",
"realpath",
"(",
"\"$basePath/$path\"",
")",
";",
"}",
"if",
"(",
"realpath",
"(",
"$",
"path",
")",
")",
"{",
"return",
"(",
"!",
"isset",
"(",
"$",
"vars",
"[",
"'HTTPS'",
"]",
")",
"||",
"$",
"vars",
"[",
"'HTTPS'",
"]",
"!=",
"'on'",
"?",
"'http://'",
":",
"'https://'",
")",
".",
"$",
"vars",
"[",
"'SERVER_NAME'",
"]",
".",
"$",
"vars",
"[",
"'CONTEXT_PREFIX'",
"]",
".",
"str_replace",
"(",
"$",
"vars",
"[",
"'CONTEXT_DOCUMENT_ROOT'",
"]",
",",
"''",
",",
"$",
"path",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Generate a URL from a path
@param string $path A valid file path
@param string[] $vars Optional (default: `$_SERVER` unless run from CLI,
in which case the method fails without this
parameter). Array must have keys `HTTPS,
SERVER_NAME, CONTEXT_PREFIX,
CONTEXT_DOCUMENT_ROOT`.
@param string|false $basePath The base path from which to start when
processing a relative path.
@return false|string The URL to that path, or `false` if the URl cannot
be computed (e.g. if run from CLI) | [
"Generate",
"a",
"URL",
"from",
"a",
"path"
] | 81e9771db3f3cfa1a757179ad447ee40703c55a3 | https://github.com/battis/data-utilities/blob/81e9771db3f3cfa1a757179ad447ee40703c55a3/src/DataUtilities.php#L193-L223 | train |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CachedDoctrineMetadataRepository.php | CachedDoctrineMetadataRepository.invoke | public function invoke($name, array $args)
{
$signature = $name . ':' . serialize($args);
if (!isset($this->cache[$signature])) {
$this->cache[$signature] = call_user_func_array(array($this->repository, $name), $args);
}
return $this->cache[$signature];
} | php | public function invoke($name, array $args)
{
$signature = $name . ':' . serialize($args);
if (!isset($this->cache[$signature])) {
$this->cache[$signature] = call_user_func_array(array($this->repository, $name), $args);
}
return $this->cache[$signature];
} | [
"public",
"function",
"invoke",
"(",
"$",
"name",
",",
"array",
"$",
"args",
")",
"{",
"$",
"signature",
"=",
"$",
"name",
".",
"':'",
".",
"serialize",
"(",
"$",
"args",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"signature",
"]",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"[",
"$",
"signature",
"]",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
"->",
"repository",
",",
"$",
"name",
")",
",",
"$",
"args",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cache",
"[",
"$",
"signature",
"]",
";",
"}"
] | Read results from cache or proxy to wrapped doctrine repository.
@param string $name
@param array $args
@return mixed | [
"Read",
"results",
"from",
"cache",
"or",
"proxy",
"to",
"wrapped",
"doctrine",
"repository",
"."
] | 236e2f52ef9cf28e71404544a1c4388f63ee535d | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CachedDoctrineMetadataRepository.php#L66-L75 | train |
anime-db/catalog-bundle | src/Form/ViewSorter.php | ViewSorter.choice | public function choice(FormView $choice)
{
$that = $this;
if ($choice->vars['compound']) {
usort($choice->children, function (FormView $a, FormView $b) use ($that) {
return $that->compare($a->vars['label'] ?: $a->vars['value'], $b->vars['label'] ?: $b->vars['value']);
});
} else {
usort($choice->vars['choices'], function (ChoiceView $a, ChoiceView $b) use ($that) {
return $that->compare($a->label ?: $a->value, $b->label ?: $b->value);
});
}
} | php | public function choice(FormView $choice)
{
$that = $this;
if ($choice->vars['compound']) {
usort($choice->children, function (FormView $a, FormView $b) use ($that) {
return $that->compare($a->vars['label'] ?: $a->vars['value'], $b->vars['label'] ?: $b->vars['value']);
});
} else {
usort($choice->vars['choices'], function (ChoiceView $a, ChoiceView $b) use ($that) {
return $that->compare($a->label ?: $a->value, $b->label ?: $b->value);
});
}
} | [
"public",
"function",
"choice",
"(",
"FormView",
"$",
"choice",
")",
"{",
"$",
"that",
"=",
"$",
"this",
";",
"if",
"(",
"$",
"choice",
"->",
"vars",
"[",
"'compound'",
"]",
")",
"{",
"usort",
"(",
"$",
"choice",
"->",
"children",
",",
"function",
"(",
"FormView",
"$",
"a",
",",
"FormView",
"$",
"b",
")",
"use",
"(",
"$",
"that",
")",
"{",
"return",
"$",
"that",
"->",
"compare",
"(",
"$",
"a",
"->",
"vars",
"[",
"'label'",
"]",
"?",
":",
"$",
"a",
"->",
"vars",
"[",
"'value'",
"]",
",",
"$",
"b",
"->",
"vars",
"[",
"'label'",
"]",
"?",
":",
"$",
"b",
"->",
"vars",
"[",
"'value'",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"usort",
"(",
"$",
"choice",
"->",
"vars",
"[",
"'choices'",
"]",
",",
"function",
"(",
"ChoiceView",
"$",
"a",
",",
"ChoiceView",
"$",
"b",
")",
"use",
"(",
"$",
"that",
")",
"{",
"return",
"$",
"that",
"->",
"compare",
"(",
"$",
"a",
"->",
"label",
"?",
":",
"$",
"a",
"->",
"value",
",",
"$",
"b",
"->",
"label",
"?",
":",
"$",
"b",
"->",
"value",
")",
";",
"}",
")",
";",
"}",
"}"
] | Sort choice.
@param FormView $choice | [
"Sort",
"choice",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Form/ViewSorter.php#L42-L54 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.updateCheck | private function updateCheck($name)
{
$filePath = Yii::getPathOfAlias('base.themes').DS.$name;
$details = $this->actionDetails($name);
if (file_exists($filePath.DS.'VERSION'))
{
$version = file_get_contents($filePath.DS.'VERSION');
if ($version != $details['latest-version'])
return true;
}
else
return true;
return false;
} | php | private function updateCheck($name)
{
$filePath = Yii::getPathOfAlias('base.themes').DS.$name;
$details = $this->actionDetails($name);
if (file_exists($filePath.DS.'VERSION'))
{
$version = file_get_contents($filePath.DS.'VERSION');
if ($version != $details['latest-version'])
return true;
}
else
return true;
return false;
} | [
"private",
"function",
"updateCheck",
"(",
"$",
"name",
")",
"{",
"$",
"filePath",
"=",
"Yii",
"::",
"getPathOfAlias",
"(",
"'base.themes'",
")",
".",
"DS",
".",
"$",
"name",
";",
"$",
"details",
"=",
"$",
"this",
"->",
"actionDetails",
"(",
"$",
"name",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
".",
"DS",
".",
"'VERSION'",
")",
")",
"{",
"$",
"version",
"=",
"file_get_contents",
"(",
"$",
"filePath",
".",
"DS",
".",
"'VERSION'",
")",
";",
"if",
"(",
"$",
"version",
"!=",
"$",
"details",
"[",
"'latest-version'",
"]",
")",
"return",
"true",
";",
"}",
"else",
"return",
"true",
";",
"return",
"false",
";",
"}"
] | Checks if an update is necessary
@param string $name
@return boolean | [
"Checks",
"if",
"an",
"update",
"is",
"necessary"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L94-L110 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.actionUpdateCheck | public function actionUpdateCheck($name=false)
{
if ($name == false)
return false;
if (defined('CII_CONFIG'))
return $this->returnError(200, Yii::t('Api.main', 'Update is not required'), false);
if ($this->updateCheck($name))
return $this->returnError(200, Yii::t('Api.main', 'Update is available'), true);
return $this->returnError(200, Yii::t('Api.main', 'Update is not required'), false);
} | php | public function actionUpdateCheck($name=false)
{
if ($name == false)
return false;
if (defined('CII_CONFIG'))
return $this->returnError(200, Yii::t('Api.main', 'Update is not required'), false);
if ($this->updateCheck($name))
return $this->returnError(200, Yii::t('Api.main', 'Update is available'), true);
return $this->returnError(200, Yii::t('Api.main', 'Update is not required'), false);
} | [
"public",
"function",
"actionUpdateCheck",
"(",
"$",
"name",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"false",
")",
"return",
"false",
";",
"if",
"(",
"defined",
"(",
"'CII_CONFIG'",
")",
")",
"return",
"$",
"this",
"->",
"returnError",
"(",
"200",
",",
"Yii",
"::",
"t",
"(",
"'Api.main'",
",",
"'Update is not required'",
")",
",",
"false",
")",
";",
"if",
"(",
"$",
"this",
"->",
"updateCheck",
"(",
"$",
"name",
")",
")",
"return",
"$",
"this",
"->",
"returnError",
"(",
"200",
",",
"Yii",
"::",
"t",
"(",
"'Api.main'",
",",
"'Update is available'",
")",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"returnError",
"(",
"200",
",",
"Yii",
"::",
"t",
"(",
"'Api.main'",
",",
"'Update is not required'",
")",
",",
"false",
")",
";",
"}"
] | Exposed action to check for an update
@param string $name
@return boolean | [
"Exposed",
"action",
"to",
"check",
"for",
"an",
"update"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L117-L129 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.actionUpdate | public function actionUpdate($name=false)
{
if ($name == false || defined('CII_CONFIG'))
return false;
// Performs an update check, and if an update is available performs the update
if ($this->updateCheck($name))
{
if (!$this->actionInstall($name))
return $this->returnError(500, Yii::t('Api.main', 'Update failed'), false);
}
// If an update is unecessary, dump the current details
return $this->actionDetails($name);
} | php | public function actionUpdate($name=false)
{
if ($name == false || defined('CII_CONFIG'))
return false;
// Performs an update check, and if an update is available performs the update
if ($this->updateCheck($name))
{
if (!$this->actionInstall($name))
return $this->returnError(500, Yii::t('Api.main', 'Update failed'), false);
}
// If an update is unecessary, dump the current details
return $this->actionDetails($name);
} | [
"public",
"function",
"actionUpdate",
"(",
"$",
"name",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"false",
"||",
"defined",
"(",
"'CII_CONFIG'",
")",
")",
"return",
"false",
";",
"// Performs an update check, and if an update is available performs the update",
"if",
"(",
"$",
"this",
"->",
"updateCheck",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"actionInstall",
"(",
"$",
"name",
")",
")",
"return",
"$",
"this",
"->",
"returnError",
"(",
"500",
",",
"Yii",
"::",
"t",
"(",
"'Api.main'",
",",
"'Update failed'",
")",
",",
"false",
")",
";",
"}",
"// If an update is unecessary, dump the current details",
"return",
"$",
"this",
"->",
"actionDetails",
"(",
"$",
"name",
")",
";",
"}"
] | Performs an update
@return boolean | [
"Performs",
"an",
"update"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L135-L149 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.actionInstall | public function actionInstall($name=false)
{
if ($name == false || defined('CII_CONFIG'))
return false;
$filePath = Yii::getPathOfAlias('base.themes').DS.$name;
$details = $this->actionDetails($name);
// If the theme is already installed, make sure it is the correct version, otherwise we'll be performing an upgrade
if ($this->actionIsInstalled($name, true))
{
if (file_exists($filePath.DS.'VERSION'))
{
$version = file_get_contents($filePath.DS.'VERSION');
if ($version == $details['latest-version'])
return true;
}
}
// Set several variables to store the various paths we'll need
$tmpPath = Yii::getPathOfAlias('application.runtime.themes').DS.$name;
$themesPath = Yii::getPathOfAlias('application.runtime').DS.'themes';
$zipPath = $themesPath.DS.$details['sha'].'.zip';
// Verify the temporary directory exists
if (!file_exists($themesPath))
mkdir($themesPath);
// Download the ZIP package to the runtime/themes temporary directory
if (!$this->downloadPackage($details['sha'], $details['file'], Yii::getPathOfAlias('application.runtime.themes')))
throw new CHttpException(500, Yii::t('Api.theme', 'Failed to download theme package from Github. Source might be down'));
$zip = new ZipArchive;
// If we can open the file
if ($zip->open($zipPath) === true)
{
// And we were able to extract it
if ($zip->extractTo($themesPath.DS.$details['sha']))
{
// Close the ZIP connection
$zip->close();
// Delete the downloaded ZIP file
unlink($zipPath);
// Move the folders around so we're operating on the bare folder, then delete the teporary folder
rename($themesPath.DS.$details['sha'].DS.'ciims-themes-'.$name.'-'.$details['latest-version'], $tmpPath);
rmdir(str_replace('.zip', '', $zipPath));
// Store the version with the theme
file_put_contents($tmpPath.'/VERSION', $details['latest-version']);
// If a theme is already installed that has that name, rename it to "$filePath-old"
if (file_exists($filePath) && is_dir($filePath))
rename($filePath, $filePath . "-old");
// Then copy over the theme from the tmpPath to the final destination path
rename($tmpPath, $filePath);
// Then purge the -old directories
if (file_exists($filePath . "-old"))
{
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filePath . "-old", FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path)
$path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());
rmdir($filePath . "-old");
}
// Purge the cache
Yii::app()->cache->delete('settings_themes');
return true;
}
}
unlink($tmpPath.'.zip');
throw new CHttpException(500, Yii::t('Api.theme', 'Unable to extract downloaded ZIP package'));
} | php | public function actionInstall($name=false)
{
if ($name == false || defined('CII_CONFIG'))
return false;
$filePath = Yii::getPathOfAlias('base.themes').DS.$name;
$details = $this->actionDetails($name);
// If the theme is already installed, make sure it is the correct version, otherwise we'll be performing an upgrade
if ($this->actionIsInstalled($name, true))
{
if (file_exists($filePath.DS.'VERSION'))
{
$version = file_get_contents($filePath.DS.'VERSION');
if ($version == $details['latest-version'])
return true;
}
}
// Set several variables to store the various paths we'll need
$tmpPath = Yii::getPathOfAlias('application.runtime.themes').DS.$name;
$themesPath = Yii::getPathOfAlias('application.runtime').DS.'themes';
$zipPath = $themesPath.DS.$details['sha'].'.zip';
// Verify the temporary directory exists
if (!file_exists($themesPath))
mkdir($themesPath);
// Download the ZIP package to the runtime/themes temporary directory
if (!$this->downloadPackage($details['sha'], $details['file'], Yii::getPathOfAlias('application.runtime.themes')))
throw new CHttpException(500, Yii::t('Api.theme', 'Failed to download theme package from Github. Source might be down'));
$zip = new ZipArchive;
// If we can open the file
if ($zip->open($zipPath) === true)
{
// And we were able to extract it
if ($zip->extractTo($themesPath.DS.$details['sha']))
{
// Close the ZIP connection
$zip->close();
// Delete the downloaded ZIP file
unlink($zipPath);
// Move the folders around so we're operating on the bare folder, then delete the teporary folder
rename($themesPath.DS.$details['sha'].DS.'ciims-themes-'.$name.'-'.$details['latest-version'], $tmpPath);
rmdir(str_replace('.zip', '', $zipPath));
// Store the version with the theme
file_put_contents($tmpPath.'/VERSION', $details['latest-version']);
// If a theme is already installed that has that name, rename it to "$filePath-old"
if (file_exists($filePath) && is_dir($filePath))
rename($filePath, $filePath . "-old");
// Then copy over the theme from the tmpPath to the final destination path
rename($tmpPath, $filePath);
// Then purge the -old directories
if (file_exists($filePath . "-old"))
{
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filePath . "-old", FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path)
$path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());
rmdir($filePath . "-old");
}
// Purge the cache
Yii::app()->cache->delete('settings_themes');
return true;
}
}
unlink($tmpPath.'.zip');
throw new CHttpException(500, Yii::t('Api.theme', 'Unable to extract downloaded ZIP package'));
} | [
"public",
"function",
"actionInstall",
"(",
"$",
"name",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"false",
"||",
"defined",
"(",
"'CII_CONFIG'",
")",
")",
"return",
"false",
";",
"$",
"filePath",
"=",
"Yii",
"::",
"getPathOfAlias",
"(",
"'base.themes'",
")",
".",
"DS",
".",
"$",
"name",
";",
"$",
"details",
"=",
"$",
"this",
"->",
"actionDetails",
"(",
"$",
"name",
")",
";",
"// If the theme is already installed, make sure it is the correct version, otherwise we'll be performing an upgrade",
"if",
"(",
"$",
"this",
"->",
"actionIsInstalled",
"(",
"$",
"name",
",",
"true",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
".",
"DS",
".",
"'VERSION'",
")",
")",
"{",
"$",
"version",
"=",
"file_get_contents",
"(",
"$",
"filePath",
".",
"DS",
".",
"'VERSION'",
")",
";",
"if",
"(",
"$",
"version",
"==",
"$",
"details",
"[",
"'latest-version'",
"]",
")",
"return",
"true",
";",
"}",
"}",
"// Set several variables to store the various paths we'll need",
"$",
"tmpPath",
"=",
"Yii",
"::",
"getPathOfAlias",
"(",
"'application.runtime.themes'",
")",
".",
"DS",
".",
"$",
"name",
";",
"$",
"themesPath",
"=",
"Yii",
"::",
"getPathOfAlias",
"(",
"'application.runtime'",
")",
".",
"DS",
".",
"'themes'",
";",
"$",
"zipPath",
"=",
"$",
"themesPath",
".",
"DS",
".",
"$",
"details",
"[",
"'sha'",
"]",
".",
"'.zip'",
";",
"// Verify the temporary directory exists",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"themesPath",
")",
")",
"mkdir",
"(",
"$",
"themesPath",
")",
";",
"// Download the ZIP package to the runtime/themes temporary directory",
"if",
"(",
"!",
"$",
"this",
"->",
"downloadPackage",
"(",
"$",
"details",
"[",
"'sha'",
"]",
",",
"$",
"details",
"[",
"'file'",
"]",
",",
"Yii",
"::",
"getPathOfAlias",
"(",
"'application.runtime.themes'",
")",
")",
")",
"throw",
"new",
"CHttpException",
"(",
"500",
",",
"Yii",
"::",
"t",
"(",
"'Api.theme'",
",",
"'Failed to download theme package from Github. Source might be down'",
")",
")",
";",
"$",
"zip",
"=",
"new",
"ZipArchive",
";",
"// If we can open the file",
"if",
"(",
"$",
"zip",
"->",
"open",
"(",
"$",
"zipPath",
")",
"===",
"true",
")",
"{",
"// And we were able to extract it",
"if",
"(",
"$",
"zip",
"->",
"extractTo",
"(",
"$",
"themesPath",
".",
"DS",
".",
"$",
"details",
"[",
"'sha'",
"]",
")",
")",
"{",
"// Close the ZIP connection",
"$",
"zip",
"->",
"close",
"(",
")",
";",
"// Delete the downloaded ZIP file",
"unlink",
"(",
"$",
"zipPath",
")",
";",
"// Move the folders around so we're operating on the bare folder, then delete the teporary folder",
"rename",
"(",
"$",
"themesPath",
".",
"DS",
".",
"$",
"details",
"[",
"'sha'",
"]",
".",
"DS",
".",
"'ciims-themes-'",
".",
"$",
"name",
".",
"'-'",
".",
"$",
"details",
"[",
"'latest-version'",
"]",
",",
"$",
"tmpPath",
")",
";",
"rmdir",
"(",
"str_replace",
"(",
"'.zip'",
",",
"''",
",",
"$",
"zipPath",
")",
")",
";",
"// Store the version with the theme",
"file_put_contents",
"(",
"$",
"tmpPath",
".",
"'/VERSION'",
",",
"$",
"details",
"[",
"'latest-version'",
"]",
")",
";",
"// If a theme is already installed that has that name, rename it to \"$filePath-old\"",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
"&&",
"is_dir",
"(",
"$",
"filePath",
")",
")",
"rename",
"(",
"$",
"filePath",
",",
"$",
"filePath",
".",
"\"-old\"",
")",
";",
"// Then copy over the theme from the tmpPath to the final destination path",
"rename",
"(",
"$",
"tmpPath",
",",
"$",
"filePath",
")",
";",
"// Then purge the -old directories",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
".",
"\"-old\"",
")",
")",
"{",
"foreach",
"(",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"filePath",
".",
"\"-old\"",
",",
"FilesystemIterator",
"::",
"SKIP_DOTS",
")",
",",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
"as",
"$",
"path",
")",
"$",
"path",
"->",
"isDir",
"(",
")",
"?",
"rmdir",
"(",
"$",
"path",
"->",
"getPathname",
"(",
")",
")",
":",
"unlink",
"(",
"$",
"path",
"->",
"getPathname",
"(",
")",
")",
";",
"rmdir",
"(",
"$",
"filePath",
".",
"\"-old\"",
")",
";",
"}",
"// Purge the cache",
"Yii",
"::",
"app",
"(",
")",
"->",
"cache",
"->",
"delete",
"(",
"'settings_themes'",
")",
";",
"return",
"true",
";",
"}",
"}",
"unlink",
"(",
"$",
"tmpPath",
".",
"'.zip'",
")",
";",
"throw",
"new",
"CHttpException",
"(",
"500",
",",
"Yii",
"::",
"t",
"(",
"'Api.theme'",
",",
"'Unable to extract downloaded ZIP package'",
")",
")",
";",
"}"
] | Installs and or updates a theme using the provided name
@return boolean | [
"Installs",
"and",
"or",
"updates",
"a",
"theme",
"using",
"the",
"provided",
"name"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L155-L235 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.actionUninstall | public function actionUninstall($name=false)
{
if ($name == false)
return false;
if ($name == 'default')
throw new CHttpException(400, Yii::t('Api.theme', 'You cannot uninstall the default theme.'));
if (!$this->actionIsInstalled($name))
return false;
$installedThemes = $this->actionInstalled();
$theme = $installedThemes[$name]['path'];
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($theme, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $path)
$path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());
return rmdir($theme);
} | php | public function actionUninstall($name=false)
{
if ($name == false)
return false;
if ($name == 'default')
throw new CHttpException(400, Yii::t('Api.theme', 'You cannot uninstall the default theme.'));
if (!$this->actionIsInstalled($name))
return false;
$installedThemes = $this->actionInstalled();
$theme = $installedThemes[$name]['path'];
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($theme, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $path)
$path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());
return rmdir($theme);
} | [
"public",
"function",
"actionUninstall",
"(",
"$",
"name",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"false",
")",
"return",
"false",
";",
"if",
"(",
"$",
"name",
"==",
"'default'",
")",
"throw",
"new",
"CHttpException",
"(",
"400",
",",
"Yii",
"::",
"t",
"(",
"'Api.theme'",
",",
"'You cannot uninstall the default theme.'",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"actionIsInstalled",
"(",
"$",
"name",
")",
")",
"return",
"false",
";",
"$",
"installedThemes",
"=",
"$",
"this",
"->",
"actionInstalled",
"(",
")",
";",
"$",
"theme",
"=",
"$",
"installedThemes",
"[",
"$",
"name",
"]",
"[",
"'path'",
"]",
";",
"$",
"iterator",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"theme",
",",
"FilesystemIterator",
"::",
"SKIP_DOTS",
")",
",",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"path",
")",
"$",
"path",
"->",
"isDir",
"(",
")",
"?",
"rmdir",
"(",
"$",
"path",
"->",
"getPathname",
"(",
")",
")",
":",
"unlink",
"(",
"$",
"path",
"->",
"getPathname",
"(",
")",
")",
";",
"return",
"rmdir",
"(",
"$",
"theme",
")",
";",
"}"
] | Uninstalls a theme by name
@return boolean | [
"Uninstalls",
"a",
"theme",
"by",
"name"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L241-L262 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.actionList | public function actionList()
{
// Don't allow theme listing in CII_CONFIG
if (defined('CII_CONFIG'))
return false;
$response = Yii::app()->cache->get('CiiMS::API::Themes::Available');
if ($response === false)
{
$url = 'https://themes.ciims.io/index.json';
$curl = new \Curl\Curl;
$response = $curl->get($url);
if ($curl->error)
throw new CHttpException(500, Yii::t('Api.index', 'Failed to retrieve remote resource.'));
$curl->close();
Yii::app()->cache->set('CiiMS::API::Themes::Available', $response, 900);
}
return $response;
} | php | public function actionList()
{
// Don't allow theme listing in CII_CONFIG
if (defined('CII_CONFIG'))
return false;
$response = Yii::app()->cache->get('CiiMS::API::Themes::Available');
if ($response === false)
{
$url = 'https://themes.ciims.io/index.json';
$curl = new \Curl\Curl;
$response = $curl->get($url);
if ($curl->error)
throw new CHttpException(500, Yii::t('Api.index', 'Failed to retrieve remote resource.'));
$curl->close();
Yii::app()->cache->set('CiiMS::API::Themes::Available', $response, 900);
}
return $response;
} | [
"public",
"function",
"actionList",
"(",
")",
"{",
"// Don't allow theme listing in CII_CONFIG",
"if",
"(",
"defined",
"(",
"'CII_CONFIG'",
")",
")",
"return",
"false",
";",
"$",
"response",
"=",
"Yii",
"::",
"app",
"(",
")",
"->",
"cache",
"->",
"get",
"(",
"'CiiMS::API::Themes::Available'",
")",
";",
"if",
"(",
"$",
"response",
"===",
"false",
")",
"{",
"$",
"url",
"=",
"'https://themes.ciims.io/index.json'",
";",
"$",
"curl",
"=",
"new",
"\\",
"Curl",
"\\",
"Curl",
";",
"$",
"response",
"=",
"$",
"curl",
"->",
"get",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"curl",
"->",
"error",
")",
"throw",
"new",
"CHttpException",
"(",
"500",
",",
"Yii",
"::",
"t",
"(",
"'Api.index'",
",",
"'Failed to retrieve remote resource.'",
")",
")",
";",
"$",
"curl",
"->",
"close",
"(",
")",
";",
"Yii",
"::",
"app",
"(",
")",
"->",
"cache",
"->",
"set",
"(",
"'CiiMS::API::Themes::Available'",
",",
"$",
"response",
",",
"900",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Lists ciims-themes that are available for download via
@return array | [
"Lists",
"ciims",
"-",
"themes",
"that",
"are",
"available",
"for",
"download",
"via"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L268-L290 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.actionDetails | public function actionDetails($name=false)
{
if ($name == false)
throw new CHttpException(400, Yii::t('Api.Theme', 'Missing theme name'));
// Fetch the data from Packagist
$data = Yii::app()->cache->get('CiiMS::API::Themes::' . $name);
if ($data === false)
{
$url = 'https://packagist.org/packages/ciims-themes/' . $name . '.json';
$curl = new \Curl\Curl;
try {
$response = $curl->get($url)->package;
} catch (Exception $e) {
throw new CHttpException(500, Yii::t('Api.index', 'Failed to retrieve data from Packagist.'));
}
if ($curl->error)
throw new CHttpException(500, Yii::t('Api.index', 'Failed to retrieve data from Packagist.'));
$curl->close();
$maintainers = array();
$versions = array();
$latestVersion = 0;
$latestVersionLiteral;
// Retrieve the version history
foreach ($response->versions as $version => $details)
{
// Ignore dev-master
if ($version == 'dev-master')
continue;
// Push the version
$versionId = preg_replace("/[^0-9]/", "", $version);
$versions[$versionId] = $version;
if ($versionId > $latestVersion)
{
$latestVersion = $versionId;
$latestVersionLiteral = $version;
}
}
// Retreive the maintainers for the latest version
foreach($response->versions->{$latestVersionLiteral}->authors as $maintainer)
{
$maintainers[] = array(
'name' => $maintainer->name,
'email' => $maintainer->email,
'homepage' => $maintainer->homepage
);
}
$data = array(
'name' => $response->name,
'description' => $response->description,
'repository' => $response->repository,
'maintainers' => $maintainers,
'latest-version' => $versions[$latestVersion],
'sha' => $response->versions->{$latestVersionLiteral}->source->reference,
'file' => $response->repository . '/archive/' . $versions[$latestVersion] . '.zip',
'downloads' => (array)$response->downloads
);
Yii::app()->cache->set('CiiMS::API::Themes::' . $name, $data, 900);
}
return $data;
} | php | public function actionDetails($name=false)
{
if ($name == false)
throw new CHttpException(400, Yii::t('Api.Theme', 'Missing theme name'));
// Fetch the data from Packagist
$data = Yii::app()->cache->get('CiiMS::API::Themes::' . $name);
if ($data === false)
{
$url = 'https://packagist.org/packages/ciims-themes/' . $name . '.json';
$curl = new \Curl\Curl;
try {
$response = $curl->get($url)->package;
} catch (Exception $e) {
throw new CHttpException(500, Yii::t('Api.index', 'Failed to retrieve data from Packagist.'));
}
if ($curl->error)
throw new CHttpException(500, Yii::t('Api.index', 'Failed to retrieve data from Packagist.'));
$curl->close();
$maintainers = array();
$versions = array();
$latestVersion = 0;
$latestVersionLiteral;
// Retrieve the version history
foreach ($response->versions as $version => $details)
{
// Ignore dev-master
if ($version == 'dev-master')
continue;
// Push the version
$versionId = preg_replace("/[^0-9]/", "", $version);
$versions[$versionId] = $version;
if ($versionId > $latestVersion)
{
$latestVersion = $versionId;
$latestVersionLiteral = $version;
}
}
// Retreive the maintainers for the latest version
foreach($response->versions->{$latestVersionLiteral}->authors as $maintainer)
{
$maintainers[] = array(
'name' => $maintainer->name,
'email' => $maintainer->email,
'homepage' => $maintainer->homepage
);
}
$data = array(
'name' => $response->name,
'description' => $response->description,
'repository' => $response->repository,
'maintainers' => $maintainers,
'latest-version' => $versions[$latestVersion],
'sha' => $response->versions->{$latestVersionLiteral}->source->reference,
'file' => $response->repository . '/archive/' . $versions[$latestVersion] . '.zip',
'downloads' => (array)$response->downloads
);
Yii::app()->cache->set('CiiMS::API::Themes::' . $name, $data, 900);
}
return $data;
} | [
"public",
"function",
"actionDetails",
"(",
"$",
"name",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"false",
")",
"throw",
"new",
"CHttpException",
"(",
"400",
",",
"Yii",
"::",
"t",
"(",
"'Api.Theme'",
",",
"'Missing theme name'",
")",
")",
";",
"// Fetch the data from Packagist",
"$",
"data",
"=",
"Yii",
"::",
"app",
"(",
")",
"->",
"cache",
"->",
"get",
"(",
"'CiiMS::API::Themes::'",
".",
"$",
"name",
")",
";",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"$",
"url",
"=",
"'https://packagist.org/packages/ciims-themes/'",
".",
"$",
"name",
".",
"'.json'",
";",
"$",
"curl",
"=",
"new",
"\\",
"Curl",
"\\",
"Curl",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"curl",
"->",
"get",
"(",
"$",
"url",
")",
"->",
"package",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"CHttpException",
"(",
"500",
",",
"Yii",
"::",
"t",
"(",
"'Api.index'",
",",
"'Failed to retrieve data from Packagist.'",
")",
")",
";",
"}",
"if",
"(",
"$",
"curl",
"->",
"error",
")",
"throw",
"new",
"CHttpException",
"(",
"500",
",",
"Yii",
"::",
"t",
"(",
"'Api.index'",
",",
"'Failed to retrieve data from Packagist.'",
")",
")",
";",
"$",
"curl",
"->",
"close",
"(",
")",
";",
"$",
"maintainers",
"=",
"array",
"(",
")",
";",
"$",
"versions",
"=",
"array",
"(",
")",
";",
"$",
"latestVersion",
"=",
"0",
";",
"$",
"latestVersionLiteral",
";",
"// Retrieve the version history",
"foreach",
"(",
"$",
"response",
"->",
"versions",
"as",
"$",
"version",
"=>",
"$",
"details",
")",
"{",
"// Ignore dev-master",
"if",
"(",
"$",
"version",
"==",
"'dev-master'",
")",
"continue",
";",
"// Push the version",
"$",
"versionId",
"=",
"preg_replace",
"(",
"\"/[^0-9]/\"",
",",
"\"\"",
",",
"$",
"version",
")",
";",
"$",
"versions",
"[",
"$",
"versionId",
"]",
"=",
"$",
"version",
";",
"if",
"(",
"$",
"versionId",
">",
"$",
"latestVersion",
")",
"{",
"$",
"latestVersion",
"=",
"$",
"versionId",
";",
"$",
"latestVersionLiteral",
"=",
"$",
"version",
";",
"}",
"}",
"// Retreive the maintainers for the latest version",
"foreach",
"(",
"$",
"response",
"->",
"versions",
"->",
"{",
"$",
"latestVersionLiteral",
"}",
"->",
"authors",
"as",
"$",
"maintainer",
")",
"{",
"$",
"maintainers",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"maintainer",
"->",
"name",
",",
"'email'",
"=>",
"$",
"maintainer",
"->",
"email",
",",
"'homepage'",
"=>",
"$",
"maintainer",
"->",
"homepage",
")",
";",
"}",
"$",
"data",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"response",
"->",
"name",
",",
"'description'",
"=>",
"$",
"response",
"->",
"description",
",",
"'repository'",
"=>",
"$",
"response",
"->",
"repository",
",",
"'maintainers'",
"=>",
"$",
"maintainers",
",",
"'latest-version'",
"=>",
"$",
"versions",
"[",
"$",
"latestVersion",
"]",
",",
"'sha'",
"=>",
"$",
"response",
"->",
"versions",
"->",
"{",
"$",
"latestVersionLiteral",
"}",
"->",
"source",
"->",
"reference",
",",
"'file'",
"=>",
"$",
"response",
"->",
"repository",
".",
"'/archive/'",
".",
"$",
"versions",
"[",
"$",
"latestVersion",
"]",
".",
"'.zip'",
",",
"'downloads'",
"=>",
"(",
"array",
")",
"$",
"response",
"->",
"downloads",
")",
";",
"Yii",
"::",
"app",
"(",
")",
"->",
"cache",
"->",
"set",
"(",
"'CiiMS::API::Themes::'",
".",
"$",
"name",
",",
"$",
"data",
",",
"900",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Retrieves the details about a particular theme
@param string $name
@return array | [
"Retrieves",
"the",
"details",
"about",
"a",
"particular",
"theme"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L297-L368 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.actionCallbackPost | public function actionCallbackPost($theme=NULL, $method=NULL)
{
$this->callback($theme, $method, $_POST);
} | php | public function actionCallbackPost($theme=NULL, $method=NULL)
{
$this->callback($theme, $method, $_POST);
} | [
"public",
"function",
"actionCallbackPost",
"(",
"$",
"theme",
"=",
"NULL",
",",
"$",
"method",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"callback",
"(",
"$",
"theme",
",",
"$",
"method",
",",
"$",
"_POST",
")",
";",
"}"
] | Allows themes to have their own dedicated callback resources for POST
This enables theme developers to not have to hack CiiMS Core in order to accomplish stuff
@param string $method The method of the current theme they want to call
@param string $theme The theme name
@return The output or action of the callback | [
"Allows",
"themes",
"to",
"have",
"their",
"own",
"dedicated",
"callback",
"resources",
"for",
"POST"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L391-L394 | train |
ciims/ciims-modules-api | controllers/ThemeController.php | ThemeController.callback | private function callback($theme, $method, $data)
{
if ($theme == NULL)
throw new CHttpException(400, Yii::t('Api.Theme', 'Missing Theme'));
if ($method == NULL)
throw new CHttpException(400, Yii::t('Api.Theme', 'Method name is missing'));
Yii::import('base.themes.' . $theme . '.Theme');
$theme = new Theme;
if (method_exists($theme, $method))
return $theme->$method($data);
throw new CHttpException(404, Yii::t('Api.Theme', 'Missing callback method.'));
} | php | private function callback($theme, $method, $data)
{
if ($theme == NULL)
throw new CHttpException(400, Yii::t('Api.Theme', 'Missing Theme'));
if ($method == NULL)
throw new CHttpException(400, Yii::t('Api.Theme', 'Method name is missing'));
Yii::import('base.themes.' . $theme . '.Theme');
$theme = new Theme;
if (method_exists($theme, $method))
return $theme->$method($data);
throw new CHttpException(404, Yii::t('Api.Theme', 'Missing callback method.'));
} | [
"private",
"function",
"callback",
"(",
"$",
"theme",
",",
"$",
"method",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"theme",
"==",
"NULL",
")",
"throw",
"new",
"CHttpException",
"(",
"400",
",",
"Yii",
"::",
"t",
"(",
"'Api.Theme'",
",",
"'Missing Theme'",
")",
")",
";",
"if",
"(",
"$",
"method",
"==",
"NULL",
")",
"throw",
"new",
"CHttpException",
"(",
"400",
",",
"Yii",
"::",
"t",
"(",
"'Api.Theme'",
",",
"'Method name is missing'",
")",
")",
";",
"Yii",
"::",
"import",
"(",
"'base.themes.'",
".",
"$",
"theme",
".",
"'.Theme'",
")",
";",
"$",
"theme",
"=",
"new",
"Theme",
";",
"if",
"(",
"method_exists",
"(",
"$",
"theme",
",",
"$",
"method",
")",
")",
"return",
"$",
"theme",
"->",
"$",
"method",
"(",
"$",
"data",
")",
";",
"throw",
"new",
"CHttpException",
"(",
"404",
",",
"Yii",
"::",
"t",
"(",
"'Api.Theme'",
",",
"'Missing callback method.'",
")",
")",
";",
"}"
] | Callback method for actionCallback and actionCallbackPost
@param string $method The method of the current theme they want to call
@param string $theme The theme name
@param array $data $_GET or $_POST
@return mixed | [
"Callback",
"method",
"for",
"actionCallback",
"and",
"actionCallbackPost"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ThemeController.php#L404-L419 | train |
covex-nn/JooS | src/JooS/Config/Adapter/Serialized.php | Adapter_Serialized.save | public function save($name, Config $config)
{
$path = $this->_getPath($name);
$data = $config->valueOf();
file_put_contents(
$path, serialize($data)
);
return true;
} | php | public function save($name, Config $config)
{
$path = $this->_getPath($name);
$data = $config->valueOf();
file_put_contents(
$path, serialize($data)
);
return true;
} | [
"public",
"function",
"save",
"(",
"$",
"name",
",",
"Config",
"$",
"config",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_getPath",
"(",
"$",
"name",
")",
";",
"$",
"data",
"=",
"$",
"config",
"->",
"valueOf",
"(",
")",
";",
"file_put_contents",
"(",
"$",
"path",
",",
"serialize",
"(",
"$",
"data",
")",
")",
";",
"return",
"true",
";",
"}"
] | Save config data
@param string $name Config name
@param Config $config Config data
@return boolean | [
"Save",
"config",
"data"
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Config/Adapter/Serialized.php#L71-L81 | train |
covex-nn/JooS | src/JooS/Config/Adapter/Serialized.php | Adapter_Serialized.delete | public function delete($name)
{
$path = $this->_getPath($name);
if (file_exists($path)) {
$result = @unlink($path);
} else {
$result = false;
}
return $result;
} | php | public function delete($name)
{
$path = $this->_getPath($name);
if (file_exists($path)) {
$result = @unlink($path);
} else {
$result = false;
}
return $result;
} | [
"public",
"function",
"delete",
"(",
"$",
"name",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_getPath",
"(",
"$",
"name",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"result",
"=",
"@",
"unlink",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Delete config data
@param string $name Config name
@return boolean | [
"Delete",
"config",
"data"
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Config/Adapter/Serialized.php#L90-L101 | train |
koolkode/json | src/Json.php | Json.encode | public static function encode($data, $forceObject = false)
{
return @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | ($forceObject ? JSON_FORCE_OBJECT : 0));
} | php | public static function encode($data, $forceObject = false)
{
return @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | ($forceObject ? JSON_FORCE_OBJECT : 0));
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"data",
",",
"$",
"forceObject",
"=",
"false",
")",
"{",
"return",
"@",
"json_encode",
"(",
"$",
"data",
",",
"JSON_UNESCAPED_SLASHES",
"|",
"JSON_UNESCAPED_UNICODE",
"|",
"(",
"$",
"forceObject",
"?",
"JSON_FORCE_OBJECT",
":",
"0",
")",
")",
";",
"}"
] | Encode the given data into a JSON string.
@param mixed $data The data to be JSON-encoded.
@param boolean $forceObject Force empty arrays to be encoded as objects?
@return string | [
"Encode",
"the",
"given",
"data",
"into",
"a",
"JSON",
"string",
"."
] | 857a6217e7e2cf4ea8270bd99d0cc35cac13dc07 | https://github.com/koolkode/json/blob/857a6217e7e2cf4ea8270bd99d0cc35cac13dc07/src/Json.php#L29-L32 | train |
koolkode/json | src/Json.php | Json.decode | public static function decode($json, $assoc = false, $maxDepth = 512)
{
$result = @json_decode($json, $assoc, $maxDepth);
if($result === NULL)
{
switch($error = json_last_error())
{
case JSON_ERROR_NONE:
return NULL;
case JSON_ERROR_CTRL_CHAR:
throw new JsonUnserializationException('An invalid control character was found in JSON-encoded data', $error);
case JSON_ERROR_DEPTH:
throw new JsonUnserializationException(sprintf('Maximum nesting depth of %u exceeded in JSON-encoded data', $maxDepth), $error);
case JSON_ERROR_SYNTAX:
throw new JsonUnserializationException('A syntax error has been detected in JSON-encoded data', $error);
default:
throw new JsonUnserializationException('An unknown error occured while unserializing JSON-encoded data', $error);
}
}
return $result;
} | php | public static function decode($json, $assoc = false, $maxDepth = 512)
{
$result = @json_decode($json, $assoc, $maxDepth);
if($result === NULL)
{
switch($error = json_last_error())
{
case JSON_ERROR_NONE:
return NULL;
case JSON_ERROR_CTRL_CHAR:
throw new JsonUnserializationException('An invalid control character was found in JSON-encoded data', $error);
case JSON_ERROR_DEPTH:
throw new JsonUnserializationException(sprintf('Maximum nesting depth of %u exceeded in JSON-encoded data', $maxDepth), $error);
case JSON_ERROR_SYNTAX:
throw new JsonUnserializationException('A syntax error has been detected in JSON-encoded data', $error);
default:
throw new JsonUnserializationException('An unknown error occured while unserializing JSON-encoded data', $error);
}
}
return $result;
} | [
"public",
"static",
"function",
"decode",
"(",
"$",
"json",
",",
"$",
"assoc",
"=",
"false",
",",
"$",
"maxDepth",
"=",
"512",
")",
"{",
"$",
"result",
"=",
"@",
"json_decode",
"(",
"$",
"json",
",",
"$",
"assoc",
",",
"$",
"maxDepth",
")",
";",
"if",
"(",
"$",
"result",
"===",
"NULL",
")",
"{",
"switch",
"(",
"$",
"error",
"=",
"json_last_error",
"(",
")",
")",
"{",
"case",
"JSON_ERROR_NONE",
":",
"return",
"NULL",
";",
"case",
"JSON_ERROR_CTRL_CHAR",
":",
"throw",
"new",
"JsonUnserializationException",
"(",
"'An invalid control character was found in JSON-encoded data'",
",",
"$",
"error",
")",
";",
"case",
"JSON_ERROR_DEPTH",
":",
"throw",
"new",
"JsonUnserializationException",
"(",
"sprintf",
"(",
"'Maximum nesting depth of %u exceeded in JSON-encoded data'",
",",
"$",
"maxDepth",
")",
",",
"$",
"error",
")",
";",
"case",
"JSON_ERROR_SYNTAX",
":",
"throw",
"new",
"JsonUnserializationException",
"(",
"'A syntax error has been detected in JSON-encoded data'",
",",
"$",
"error",
")",
";",
"default",
":",
"throw",
"new",
"JsonUnserializationException",
"(",
"'An unknown error occured while unserializing JSON-encoded data'",
",",
"$",
"error",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Decode the given JSON string into a PHP data structure.
@param string $json The JSON-encoded input data.
@param boolean $assoc Serialize JSON objects into PHP arrays?
@param integer $maxDepth Maximum nesting depth of JSON input.
@return mixed
@throws JsonUnserializationException When any error occurs during unserialization. The exceptions
code is set to the error code returned by json_last_error(). | [
"Decode",
"the",
"given",
"JSON",
"string",
"into",
"a",
"PHP",
"data",
"structure",
"."
] | 857a6217e7e2cf4ea8270bd99d0cc35cac13dc07 | https://github.com/koolkode/json/blob/857a6217e7e2cf4ea8270bd99d0cc35cac13dc07/src/Json.php#L45-L67 | train |
miBadger/miBadger.Pagination | src/Pagination.php | Pagination.get | public function get($index)
{
return array_slice($this->items, $index * $this->itemsPerPage, $this->itemsPerPage);
} | php | public function get($index)
{
return array_slice($this->items, $index * $this->itemsPerPage, $this->itemsPerPage);
} | [
"public",
"function",
"get",
"(",
"$",
"index",
")",
"{",
"return",
"array_slice",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"index",
"*",
"$",
"this",
"->",
"itemsPerPage",
",",
"$",
"this",
"->",
"itemsPerPage",
")",
";",
"}"
] | Returns the items on the given page number.
@param int $index
@return mixed[] the items on the given page number. | [
"Returns",
"the",
"items",
"on",
"the",
"given",
"page",
"number",
"."
] | 4c9a528a3e3ef9b16f6d1db375b17d5a9fa1c447 | https://github.com/miBadger/miBadger.Pagination/blob/4c9a528a3e3ef9b16f6d1db375b17d5a9fa1c447/src/Pagination.php#L62-L65 | train |
eureka-framework/component-http | src/Http/File.php | File.useName | public function useName($name)
{
if (empty($name)) {
throw new \Exception('Given name is empty!');
}
if (!isset($_FILES[$name])) {
throw new \Exception('Given name not exists in $_FILES var!');
}
$this->data = $_FILES[$name];
return $this;
} | php | public function useName($name)
{
if (empty($name)) {
throw new \Exception('Given name is empty!');
}
if (!isset($_FILES[$name])) {
throw new \Exception('Given name not exists in $_FILES var!');
}
$this->data = $_FILES[$name];
return $this;
} | [
"public",
"function",
"useName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Given name is empty!'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"_FILES",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Given name not exists in $_FILES var!'",
")",
";",
"}",
"$",
"this",
"->",
"data",
"=",
"$",
"_FILES",
"[",
"$",
"name",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Use name as default in File's methods.
@param string $name
@return self
@throws \Exception | [
"Use",
"name",
"as",
"default",
"in",
"File",
"s",
"methods",
"."
] | 698c3b73581a9703a9c932890c57e50f8774607a | https://github.com/eureka-framework/component-http/blob/698c3b73581a9703a9c932890c57e50f8774607a/src/Http/File.php#L44-L57 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.