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 list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
grrr-amsterdam/garp3 | library/Garp/Adobe/InDesign/Storage.php | Garp_Adobe_InDesign_Storage.extract | public function extract() {
$zip = new ZipArchive();
$res = $zip->open($this->_sourcePath);
if ($res === true) {
$zip->extractTo($this->_workingDir);
$zip->close();
} else {
throw new Exception('Could not open archive ' . $this->_sourcePath);
}
} | php | public function extract() {
$zip = new ZipArchive();
$res = $zip->open($this->_sourcePath);
if ($res === true) {
$zip->extractTo($this->_workingDir);
$zip->close();
} else {
throw new Exception('Could not open archive ' . $this->_sourcePath);
}
} | [
"public",
"function",
"extract",
"(",
")",
"{",
"$",
"zip",
"=",
"new",
"ZipArchive",
"(",
")",
";",
"$",
"res",
"=",
"$",
"zip",
"->",
"open",
"(",
"$",
"this",
"->",
"_sourcePath",
")",
";",
"if",
"(",
"$",
"res",
"===",
"true",
")",
"{",
"$"... | Extract .idml file and place it in the working directory.
@return void | [
"Extract",
".",
"idml",
"file",
"and",
"place",
"it",
"in",
"the",
"working",
"directory",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Adobe/InDesign/Storage.php#L44-L54 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Google/Maps.php | Garp_Service_Google_Maps.fetchLocation | public function fetchLocation($address, $country = null) {
$params = array(
'address' => urlencode($address),
'sensor' => 'false'
);
if ($country) {
$params['components'] = 'country:' . $country;
}
$url = self::API_URL . http_build_query($params);
$rawResponse = file_get_contents($url);
$response = new Garp_Service_Google_Maps_Response($rawResponse);
return $response;
} | php | public function fetchLocation($address, $country = null) {
$params = array(
'address' => urlencode($address),
'sensor' => 'false'
);
if ($country) {
$params['components'] = 'country:' . $country;
}
$url = self::API_URL . http_build_query($params);
$rawResponse = file_get_contents($url);
$response = new Garp_Service_Google_Maps_Response($rawResponse);
return $response;
} | [
"public",
"function",
"fetchLocation",
"(",
"$",
"address",
",",
"$",
"country",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'address'",
"=>",
"urlencode",
"(",
"$",
"address",
")",
",",
"'sensor'",
"=>",
"'false'",
")",
";",
"if",
"(",
... | Fetches location data for given address component
@param String $address The address string, can be anything: zip, street, etc.
@return Garp_Service_Google_Maps_Response The elaborate location data from Google. | [
"Fetches",
"location",
"data",
"for",
"given",
"address",
"component"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Google/Maps.php#L28-L43 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/Php/Model/Base.php | Garp_Spawn_Php_Model_Base._convertToArray | protected function _convertToArray($obj) {
$arr = array();
$arrObj = is_object($obj) ? get_object_vars($obj) : $obj;
foreach ($arrObj as $key => $val) {
if (is_object($val)) {
switch (get_class($val)) {
case 'Garp_Spawn_Relation_Set':
$val = $val->getRelations();
break;
case 'Garp_Spawn_Behaviors':
$val = $val->getBehaviors();
break;
case 'Garp_Spawn_Fields':
$val = $val->getFields();
}
$val = $this->_convertToArray($val);
} elseif (is_array($val)) {
$val = $this->_convertToArray($val);
}
$arr[$key] = $val;
}
return $arr;
} | php | protected function _convertToArray($obj) {
$arr = array();
$arrObj = is_object($obj) ? get_object_vars($obj) : $obj;
foreach ($arrObj as $key => $val) {
if (is_object($val)) {
switch (get_class($val)) {
case 'Garp_Spawn_Relation_Set':
$val = $val->getRelations();
break;
case 'Garp_Spawn_Behaviors':
$val = $val->getBehaviors();
break;
case 'Garp_Spawn_Fields':
$val = $val->getFields();
}
$val = $this->_convertToArray($val);
} elseif (is_array($val)) {
$val = $this->_convertToArray($val);
}
$arr[$key] = $val;
}
return $arr;
} | [
"protected",
"function",
"_convertToArray",
"(",
"$",
"obj",
")",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"$",
"arrObj",
"=",
"is_object",
"(",
"$",
"obj",
")",
"?",
"get_object_vars",
"(",
"$",
"obj",
")",
":",
"$",
"obj",
";",
"foreach",
"(... | Extracts the public properties from an iteratable object
@param mixed $obj At first, feed this a Garp_Spawn_Model_Abstract, after which
it calls itself with an array.
@return array | [
"Extracts",
"the",
"public",
"properties",
"from",
"an",
"iteratable",
"object"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Php/Model/Base.php#L215-L240 | train |
grrr-amsterdam/garp3 | library/Garp/Controller/Plugin/Auth.php | Garp_Controller_Plugin_Auth.postDispatch | public function postDispatch(Zend_Controller_Request_Abstract $request) {
$store = Garp_Auth::getInstance()->getStore();
if ($store instanceof Garp_Store_Cookie && $store->isModified()) {
$store->writeCookie();
}
} | php | public function postDispatch(Zend_Controller_Request_Abstract $request) {
$store = Garp_Auth::getInstance()->getStore();
if ($store instanceof Garp_Store_Cookie && $store->isModified()) {
$store->writeCookie();
}
} | [
"public",
"function",
"postDispatch",
"(",
"Zend_Controller_Request_Abstract",
"$",
"request",
")",
"{",
"$",
"store",
"=",
"Garp_Auth",
"::",
"getInstance",
"(",
")",
"->",
"getStore",
"(",
")",
";",
"if",
"(",
"$",
"store",
"instanceof",
"Garp_Store_Cookie",
... | Is called after an action is dispatched by the dispatcher.
Here we force a write to the Auth cookie. Because user data may be
read in the view, the cookie will otherwise not be written until
headers are already sent.
@param Zend_Controller_Request_Abstract $request
@return Void | [
"Is",
"called",
"after",
"an",
"action",
"is",
"dispatched",
"by",
"the",
"dispatcher",
".",
"Here",
"we",
"force",
"a",
"write",
"to",
"the",
"Auth",
"cookie",
".",
"Because",
"user",
"data",
"may",
"be",
"read",
"in",
"the",
"view",
"the",
"cookie",
... | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Plugin/Auth.php#L52-L57 | train |
grrr-amsterdam/garp3 | library/Garp/Controller/Plugin/Auth.php | Garp_Controller_Plugin_Auth._isAllowed | protected function _isAllowed() {
// check if a user may view this page
$request = $this->getRequest();
return Garp_Auth::getInstance()->isAllowed(
$request->getControllerName(),
$request->getActionName()
);
} | php | protected function _isAllowed() {
// check if a user may view this page
$request = $this->getRequest();
return Garp_Auth::getInstance()->isAllowed(
$request->getControllerName(),
$request->getActionName()
);
} | [
"protected",
"function",
"_isAllowed",
"(",
")",
"{",
"// check if a user may view this page",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"return",
"Garp_Auth",
"::",
"getInstance",
"(",
")",
"->",
"isAllowed",
"(",
"$",
"request",
"-... | See if a role is allowed to execute the current request.
@return Boolean | [
"See",
"if",
"a",
"role",
"is",
"allowed",
"to",
"execute",
"the",
"current",
"request",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Plugin/Auth.php#L63-L70 | train |
grrr-amsterdam/garp3 | library/Garp/Controller/Plugin/Auth.php | Garp_Controller_Plugin_Auth._redirectToLogin | protected function _redirectToLogin() {
$this->_storeTargetUrl();
$auth = Garp_Auth::getInstance();
$authVars = $auth->getConfigValues();
$flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
$flashMessenger->addMessage(!$auth->isLoggedIn() ?
__($authVars['notLoggedInMsg']) : __($authVars['noPermissionMsg']));
// Make sure the redirect is not cached
Zend_Controller_Action_HelperBroker::getStaticHelper('cache')->setNoCacheHeaders(
$this->getResponse());
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirectMethod = 'gotoUrlAndExit';
$redirectParams = array('/g/auth/login');
if (!empty($authVars['login']['route'])) {
$redirectMethod = 'gotoRoute';
$redirectParams = array(array(), $authVars['login']['route']);
}
call_user_func_array(array($redirector, $redirectMethod), $redirectParams);
} | php | protected function _redirectToLogin() {
$this->_storeTargetUrl();
$auth = Garp_Auth::getInstance();
$authVars = $auth->getConfigValues();
$flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
$flashMessenger->addMessage(!$auth->isLoggedIn() ?
__($authVars['notLoggedInMsg']) : __($authVars['noPermissionMsg']));
// Make sure the redirect is not cached
Zend_Controller_Action_HelperBroker::getStaticHelper('cache')->setNoCacheHeaders(
$this->getResponse());
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirectMethod = 'gotoUrlAndExit';
$redirectParams = array('/g/auth/login');
if (!empty($authVars['login']['route'])) {
$redirectMethod = 'gotoRoute';
$redirectParams = array(array(), $authVars['login']['route']);
}
call_user_func_array(array($redirector, $redirectMethod), $redirectParams);
} | [
"protected",
"function",
"_redirectToLogin",
"(",
")",
"{",
"$",
"this",
"->",
"_storeTargetUrl",
"(",
")",
";",
"$",
"auth",
"=",
"Garp_Auth",
"::",
"getInstance",
"(",
")",
";",
"$",
"authVars",
"=",
"$",
"auth",
"->",
"getConfigValues",
"(",
")",
";",... | Redirect user to login page
@return Void | [
"Redirect",
"user",
"to",
"login",
"page"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Plugin/Auth.php#L76-L99 | train |
grrr-amsterdam/garp3 | library/Garp/Controller/Plugin/Auth.php | Garp_Controller_Plugin_Auth._storeTargetUrl | protected function _storeTargetUrl() {
$request = $this->getRequest();
// Only store targetUrl when method = GET. A redirect to a POST request is useless.
if (!$request->isGet()) {
return;
}
// Allow ?targetUrl=/path/to/elsewhere on any URL
if (!$targetUrl = $request->getParam('targetUrl')) {
$targetUrl = $request->getRequestUri();
$baseUrl = $request->getBaseUrl();
/**
* Remove the baseUrl from the targetUrl. This is neccessary
* when Garp is installed in a subfolder.
*/
$targetUrl = Garp_Util_String::strReplaceOnce($baseUrl, '', $targetUrl);
}
if ($targetUrl !== '/favicon.ico' && !$request->isXmlHttpRequest()) {
$store = Garp_Auth::getInstance()->getStore();
$store->targetUrl = $targetUrl;
}
} | php | protected function _storeTargetUrl() {
$request = $this->getRequest();
// Only store targetUrl when method = GET. A redirect to a POST request is useless.
if (!$request->isGet()) {
return;
}
// Allow ?targetUrl=/path/to/elsewhere on any URL
if (!$targetUrl = $request->getParam('targetUrl')) {
$targetUrl = $request->getRequestUri();
$baseUrl = $request->getBaseUrl();
/**
* Remove the baseUrl from the targetUrl. This is neccessary
* when Garp is installed in a subfolder.
*/
$targetUrl = Garp_Util_String::strReplaceOnce($baseUrl, '', $targetUrl);
}
if ($targetUrl !== '/favicon.ico' && !$request->isXmlHttpRequest()) {
$store = Garp_Auth::getInstance()->getStore();
$store->targetUrl = $targetUrl;
}
} | [
"protected",
"function",
"_storeTargetUrl",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// Only store targetUrl when method = GET. A redirect to a POST request is useless.",
"if",
"(",
"!",
"$",
"request",
"->",
"isGet",
"(",
... | Store targetUrl in session. After login the user is redirected
back to this url.
@return Void | [
"Store",
"targetUrl",
"in",
"session",
".",
"After",
"login",
"the",
"user",
"is",
"redirected",
"back",
"to",
"this",
"url",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Plugin/Auth.php#L114-L136 | train |
grrr-amsterdam/garp3 | library/Garp/Application.php | Garp_Application._loadConfig | protected function _loadConfig($file) {
$suffix = pathinfo($file, PATHINFO_EXTENSION);
$suffix = ($suffix === 'dist') ?
pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION) : $suffix;
if ($suffix == 'ini') {
$config = Garp_Config_Ini::getCached($file, $this->getEnvironment())->toArray();
} else {
$config = parent::_loadConfig($file);
}
return $config;
} | php | protected function _loadConfig($file) {
$suffix = pathinfo($file, PATHINFO_EXTENSION);
$suffix = ($suffix === 'dist') ?
pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION) : $suffix;
if ($suffix == 'ini') {
$config = Garp_Config_Ini::getCached($file, $this->getEnvironment())->toArray();
} else {
$config = parent::_loadConfig($file);
}
return $config;
} | [
"protected",
"function",
"_loadConfig",
"(",
"$",
"file",
")",
"{",
"$",
"suffix",
"=",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
";",
"$",
"suffix",
"=",
"(",
"$",
"suffix",
"===",
"'dist'",
")",
"?",
"pathinfo",
"(",
"basename",
"... | Load configuration file of options.
Optionally will cache the configuration.
@param string $file
@throws Zend_Application_Exception When invalid configuration file is provided
@return array | [
"Load",
"configuration",
"file",
"of",
"options",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Application.php#L62-L72 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Admin.php | Garp_Cli_Command_Admin.add | public function add(array $args = array()) {
$ini = Garp_Auth::getInstance()->getConfigValues();
if (empty($ini['adapters']['db'])) {
Garp_Cli::errorOut('Error: DB adapter is not configured in application.ini.');
} elseif (empty($ini['adapters']['db']['identityColumn'])
|| empty($ini['adapters']['db']['credentialColumn'])
) {
Garp_Cli::errorOut(
'Error: identityColumn or credentialColumn not configured in application.ini'
);
} else {
$newUserData = array(
'role' => 'admin'
);
$promptData = array();
// Pull required fields from Spawner config
$modelSet = Garp_Spawn_Model_Set::getInstance();
$userModelConfig = $modelSet['User'];
$requiredFields = $userModelConfig->fields->getFields('required', true);
foreach ($requiredFields as $field) {
if ($field->origin == 'config' && $field->name !== 'id') {
$promptData[] = $field->name;
} elseif ($field->origin == 'relation') {
Garp_Cli::errorOut(
'Field ' . $field->name .
' is required but must be filled by way of relation. ' .
'This makes it impossible to create an admin from the commandline.'
);
}
}
if (!in_array($ini['adapters']['db']['identityColumn'], $promptData)) {
$promptData[] = $ini['adapters']['db']['identityColumn'];
}
// prompt for the new data
Garp_Cli::lineOut('Please fill the following columns:');
foreach ($promptData as $key) {
$newUserData[$key] = trim(Garp_Cli::prompt($key . ':'));
}
$newAuthLocalData = array(
'password' => trim(Garp_Cli::prompt('Choose a password:'))
);
/**
* A lot of assumptions are made here;
* - a users table is available, as well as a User model
* - an auth_local table is available, following the conventions set by Garp
* - the users table has an id, name, email and role column, while the password
* column resides in the auth_local table
*
* While all this is the preferred method, it's entirely possible to circumvent these
* conventions and come up with project-specific standards.
* In that case however, this CLI command is not for you.
*/
$user = new Model_User();
try {
$id = $user->insert($newUserData);
$authLocal = new Model_AuthLocal();
$newAuthLocalData['user_id'] = $id;
if ($authLocal->insert($newAuthLocalData)) {
Garp_Cli::lineOut('Successfully created the administrator. (id: ' . $id . ')');
} else {
Garp_Cli::errorOut('Error: could not create administrator.');
}
} catch (Zend_Db_Statement_Exception $e) {
if (strpos($e->getMessage(), 'Duplicate entry') !== false
&& strpos($e->getMessage(), 'email_unique') !== false
) {
Garp_Cli::errorOut(
'Error: this email address is already in use. ' .
'Maybe you meant to use Garp Admin make?'
);
} else {
throw $e;
}
}
}
} | php | public function add(array $args = array()) {
$ini = Garp_Auth::getInstance()->getConfigValues();
if (empty($ini['adapters']['db'])) {
Garp_Cli::errorOut('Error: DB adapter is not configured in application.ini.');
} elseif (empty($ini['adapters']['db']['identityColumn'])
|| empty($ini['adapters']['db']['credentialColumn'])
) {
Garp_Cli::errorOut(
'Error: identityColumn or credentialColumn not configured in application.ini'
);
} else {
$newUserData = array(
'role' => 'admin'
);
$promptData = array();
// Pull required fields from Spawner config
$modelSet = Garp_Spawn_Model_Set::getInstance();
$userModelConfig = $modelSet['User'];
$requiredFields = $userModelConfig->fields->getFields('required', true);
foreach ($requiredFields as $field) {
if ($field->origin == 'config' && $field->name !== 'id') {
$promptData[] = $field->name;
} elseif ($field->origin == 'relation') {
Garp_Cli::errorOut(
'Field ' . $field->name .
' is required but must be filled by way of relation. ' .
'This makes it impossible to create an admin from the commandline.'
);
}
}
if (!in_array($ini['adapters']['db']['identityColumn'], $promptData)) {
$promptData[] = $ini['adapters']['db']['identityColumn'];
}
// prompt for the new data
Garp_Cli::lineOut('Please fill the following columns:');
foreach ($promptData as $key) {
$newUserData[$key] = trim(Garp_Cli::prompt($key . ':'));
}
$newAuthLocalData = array(
'password' => trim(Garp_Cli::prompt('Choose a password:'))
);
/**
* A lot of assumptions are made here;
* - a users table is available, as well as a User model
* - an auth_local table is available, following the conventions set by Garp
* - the users table has an id, name, email and role column, while the password
* column resides in the auth_local table
*
* While all this is the preferred method, it's entirely possible to circumvent these
* conventions and come up with project-specific standards.
* In that case however, this CLI command is not for you.
*/
$user = new Model_User();
try {
$id = $user->insert($newUserData);
$authLocal = new Model_AuthLocal();
$newAuthLocalData['user_id'] = $id;
if ($authLocal->insert($newAuthLocalData)) {
Garp_Cli::lineOut('Successfully created the administrator. (id: ' . $id . ')');
} else {
Garp_Cli::errorOut('Error: could not create administrator.');
}
} catch (Zend_Db_Statement_Exception $e) {
if (strpos($e->getMessage(), 'Duplicate entry') !== false
&& strpos($e->getMessage(), 'email_unique') !== false
) {
Garp_Cli::errorOut(
'Error: this email address is already in use. ' .
'Maybe you meant to use Garp Admin make?'
);
} else {
throw $e;
}
}
}
} | [
"public",
"function",
"add",
"(",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"ini",
"=",
"Garp_Auth",
"::",
"getInstance",
"(",
")",
"->",
"getConfigValues",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"ini",
"[",
"'adapters'",
"... | Add a new admin to the system
@param array $args
@return void | [
"Add",
"a",
"new",
"admin",
"to",
"the",
"system"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Admin.php#L16-L96 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Admin.php | Garp_Cli_Command_Admin.make | public function make(array $args = array()) {
$userModel = new Model_User();
if (!empty($args)) {
$id = $args[0];
} else {
$id = Garp_Cli::prompt('What is the id or email address of the user?');
}
$select = $userModel->select();
if (is_numeric($id)) {
$filterColumn = 'id';
} else {
$filterColumn = 'email';
}
$select->where($filterColumn . ' = ?', $id);
$user = $userModel->fetchRow($select);
if (!$user) {
Garp_Cli::errorOut('Error: could not find user with ' . $filterColumn . ' ' . $id);
} else {
$user->role = 'admin';
if ($user->save()) {
// For completeness sake, check if the user has an AuthLocal
// record. We disregard the fact wether the user already has any
// of the other Auth- records.
$authLocalModel = new Model_AuthLocal();
$authLocalRecord = $authLocalModel->fetchRow(
$authLocalModel->select()->where('user_id = ?', $user->id)
);
if (!$authLocalRecord) {
$newAuthLocalData = array(
'password' => trim(Garp_Cli::prompt('Choose a password:')),
'user_id' => $user->id
);
$authLocalModel->insert($newAuthLocalData);
}
Garp_Cli::lineOut(
'User with ' . $filterColumn . ' ' . $id .
' is now administrator'
);
} else {
Garp_Cli::errorOut(
'Error: could not make user with ' . $filterColumn . ' ' . $id .
' administrator'
);
}
}
} | php | public function make(array $args = array()) {
$userModel = new Model_User();
if (!empty($args)) {
$id = $args[0];
} else {
$id = Garp_Cli::prompt('What is the id or email address of the user?');
}
$select = $userModel->select();
if (is_numeric($id)) {
$filterColumn = 'id';
} else {
$filterColumn = 'email';
}
$select->where($filterColumn . ' = ?', $id);
$user = $userModel->fetchRow($select);
if (!$user) {
Garp_Cli::errorOut('Error: could not find user with ' . $filterColumn . ' ' . $id);
} else {
$user->role = 'admin';
if ($user->save()) {
// For completeness sake, check if the user has an AuthLocal
// record. We disregard the fact wether the user already has any
// of the other Auth- records.
$authLocalModel = new Model_AuthLocal();
$authLocalRecord = $authLocalModel->fetchRow(
$authLocalModel->select()->where('user_id = ?', $user->id)
);
if (!$authLocalRecord) {
$newAuthLocalData = array(
'password' => trim(Garp_Cli::prompt('Choose a password:')),
'user_id' => $user->id
);
$authLocalModel->insert($newAuthLocalData);
}
Garp_Cli::lineOut(
'User with ' . $filterColumn . ' ' . $id .
' is now administrator'
);
} else {
Garp_Cli::errorOut(
'Error: could not make user with ' . $filterColumn . ' ' . $id .
' administrator'
);
}
}
} | [
"public",
"function",
"make",
"(",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"userModel",
"=",
"new",
"Model_User",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"args",
")",
")",
"{",
"$",
"id",
"=",
"$",
"args",
"[",
... | Make an existing user admin
@param array $args
@return void | [
"Make",
"an",
"existing",
"user",
"admin"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Admin.php#L105-L150 | train |
grrr-amsterdam/garp3 | library/Garp/Auth/Factory.php | Garp_Auth_Factory.getAdapter | public static function getAdapter($key) {
$config = Zend_Registry::get('config');
if (!$config->auth || !$config->auth->adapters) {
throw new Garp_Auth_Exception(self::EXCEPTION_NO_ADAPTERS_CONFIGURED);
}
$key = strtolower($key);
if (!$config->auth->adapters->{$key}) {
throw new Garp_Auth_Exception(sprintf(self::EXCEPTION_KEY_NOT_FOUND, $key));
}
$classKey = $config->auth->adapters->{$key}->class;
if (!$classKey) {
$classKey = $key;
}
$className = strpos($classKey, '_') === false ?
self::AUTH_NAMESPACE . ucfirst($classKey) : $classKey;
$obj = new $className();
if (!$obj instanceof Garp_Auth_Adapter_Abstract) {
throw new Garp_Auth_Exception(sprintf(self::EXCEPTION_INVALID_CLASS, $className));
}
return $obj;
} | php | public static function getAdapter($key) {
$config = Zend_Registry::get('config');
if (!$config->auth || !$config->auth->adapters) {
throw new Garp_Auth_Exception(self::EXCEPTION_NO_ADAPTERS_CONFIGURED);
}
$key = strtolower($key);
if (!$config->auth->adapters->{$key}) {
throw new Garp_Auth_Exception(sprintf(self::EXCEPTION_KEY_NOT_FOUND, $key));
}
$classKey = $config->auth->adapters->{$key}->class;
if (!$classKey) {
$classKey = $key;
}
$className = strpos($classKey, '_') === false ?
self::AUTH_NAMESPACE . ucfirst($classKey) : $classKey;
$obj = new $className();
if (!$obj instanceof Garp_Auth_Adapter_Abstract) {
throw new Garp_Auth_Exception(sprintf(self::EXCEPTION_INVALID_CLASS, $className));
}
return $obj;
} | [
"public",
"static",
"function",
"getAdapter",
"(",
"$",
"key",
")",
"{",
"$",
"config",
"=",
"Zend_Registry",
"::",
"get",
"(",
"'config'",
")",
";",
"if",
"(",
"!",
"$",
"config",
"->",
"auth",
"||",
"!",
"$",
"config",
"->",
"auth",
"->",
"adapters... | Retrieve a specified Zend_Auth_Adapter_Interface object.
@param String $key The authentication key. An adapter must be stored under
auth.adapters.{$key}.
@return Garp_Auth | [
"Retrieve",
"a",
"specified",
"Zend_Auth_Adapter_Interface",
"object",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Factory.php#L31-L53 | train |
grrr-amsterdam/garp3 | library/Garp/Content/Export/Excel.php | Garp_Content_Export_Excel._addRow | protected function _addRow(PHPExcel $phpexcel, array $row, $rowIndex) {
$col = 0;
foreach ($row as $key => $value) {
$colIndex = $col++;
if (is_array($value)) {
$rowset = $value;
$value = array();
foreach ($rowset as $row) {
if (is_array($row)) {
$values = array_values($row);
$values = implode(' : ', $values);
} else {
$values = $row;
}
$value[] = $values;
}
$value = implode("\n", $value);
}
$phpexcel->getActiveSheet()->setCellValueByColumnAndRow($colIndex, $rowIndex, $value);
}
} | php | protected function _addRow(PHPExcel $phpexcel, array $row, $rowIndex) {
$col = 0;
foreach ($row as $key => $value) {
$colIndex = $col++;
if (is_array($value)) {
$rowset = $value;
$value = array();
foreach ($rowset as $row) {
if (is_array($row)) {
$values = array_values($row);
$values = implode(' : ', $values);
} else {
$values = $row;
}
$value[] = $values;
}
$value = implode("\n", $value);
}
$phpexcel->getActiveSheet()->setCellValueByColumnAndRow($colIndex, $rowIndex, $value);
}
} | [
"protected",
"function",
"_addRow",
"(",
"PHPExcel",
"$",
"phpexcel",
",",
"array",
"$",
"row",
",",
"$",
"rowIndex",
")",
"{",
"$",
"col",
"=",
"0",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"colIndex",
... | Add row to spreadsheet
@param PHPExcel $phpexcel
@param array $row
@param string $rowIndex Character describing the row index
@return void | [
"Add",
"row",
"to",
"spreadsheet"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Export/Excel.php#L103-L123 | train |
grrr-amsterdam/garp3 | library/Garp/File/ZipArchive.php | Garp_File_ZipArchive.addDirectory | public function addDirectory($source) {
$source = str_replace('\\', '/', realpath($source));
if (is_dir($source) === true) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
continue;
if (!is_link($file)) {
$file = realpath($file);
}
if (!is_link($file) && is_dir($file)) {
$this->addEmptyDir(str_replace($source . '/', '', $file . '/'));
} else if (is_link($file)) {
// @fixme This actually does not work. It will create a file in the zip, but it
// won't be a link pointing somewhere.
// I have not found a way to add a working symlink to a zip archive.
$this->addFile($file, str_replace($source . '/', '', $file));
} else if (is_file($file)) {
$this->addFromString(str_replace($source . '/', '', $file),
file_get_contents($file));
}
}
} else if (is_file($source) === true) {
$this->addFromString(basename($source), file_get_contents($source));
}
} | php | public function addDirectory($source) {
$source = str_replace('\\', '/', realpath($source));
if (is_dir($source) === true) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
continue;
if (!is_link($file)) {
$file = realpath($file);
}
if (!is_link($file) && is_dir($file)) {
$this->addEmptyDir(str_replace($source . '/', '', $file . '/'));
} else if (is_link($file)) {
// @fixme This actually does not work. It will create a file in the zip, but it
// won't be a link pointing somewhere.
// I have not found a way to add a working symlink to a zip archive.
$this->addFile($file, str_replace($source . '/', '', $file));
} else if (is_file($file)) {
$this->addFromString(str_replace($source . '/', '', $file),
file_get_contents($file));
}
}
} else if (is_file($source) === true) {
$this->addFromString(basename($source), file_get_contents($source));
}
} | [
"public",
"function",
"addDirectory",
"(",
"$",
"source",
")",
"{",
"$",
"source",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"realpath",
"(",
"$",
"source",
")",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"source",
")",
"===",
"true",
")",
... | Add the complete contents of a directory, recursively. | [
"Add",
"the",
"complete",
"contents",
"of",
"a",
"directory",
"recursively",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/File/ZipArchive.php#L15-L48 | train |
grrr-amsterdam/garp3 | library/Garp/Cli.php | Garp_Cli.lineOut | public static function lineOut($s, $color = null, $appendNewline = true, $echo = true) {
if ($color) {
self::addStringColoring($s, $color);
}
$out = "{$s}" . ($appendNewline ? "\n" : '');
if ($echo && !static::$_quiet) {
print $out;
} else {
return $out;
}
} | php | public static function lineOut($s, $color = null, $appendNewline = true, $echo = true) {
if ($color) {
self::addStringColoring($s, $color);
}
$out = "{$s}" . ($appendNewline ? "\n" : '');
if ($echo && !static::$_quiet) {
print $out;
} else {
return $out;
}
} | [
"public",
"static",
"function",
"lineOut",
"(",
"$",
"s",
",",
"$",
"color",
"=",
"null",
",",
"$",
"appendNewline",
"=",
"true",
",",
"$",
"echo",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"color",
")",
"{",
"self",
"::",
"addStringColoring",
"(",
"$... | Print line.
@param string $s The string.
@param string $color Show string in color?
@param bool $appendNewline Wether to add a newline character
@param bool $echo Wether to echo
@return void | [
"Print",
"line",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli.php#L58-L68 | train |
grrr-amsterdam/garp3 | library/Garp/Cli.php | Garp_Cli.errorOut | public static function errorOut($s) {
// Always output errors
$oldQuiet = self::getQuiet();
self::setQuiet(false);
self::lineOut($s, self::RED);
self::setQuiet($oldQuiet);
} | php | public static function errorOut($s) {
// Always output errors
$oldQuiet = self::getQuiet();
self::setQuiet(false);
self::lineOut($s, self::RED);
self::setQuiet($oldQuiet);
} | [
"public",
"static",
"function",
"errorOut",
"(",
"$",
"s",
")",
"{",
"// Always output errors",
"$",
"oldQuiet",
"=",
"self",
"::",
"getQuiet",
"(",
")",
";",
"self",
"::",
"setQuiet",
"(",
"false",
")",
";",
"self",
"::",
"lineOut",
"(",
"$",
"s",
","... | Print line in red.
@param string $s
@return void | [
"Print",
"line",
"in",
"red",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli.php#L76-L83 | train |
grrr-amsterdam/garp3 | library/Garp/Cli.php | Garp_Cli.prompt | public static function prompt($prompt = '', $trim = true) {
$prompt && self::lineOut($prompt);
self::lineOut('> ', null, false);
$response = fgets(STDIN);
if ($trim) {
$response = trim($response);
}
return $response;
} | php | public static function prompt($prompt = '', $trim = true) {
$prompt && self::lineOut($prompt);
self::lineOut('> ', null, false);
$response = fgets(STDIN);
if ($trim) {
$response = trim($response);
}
return $response;
} | [
"public",
"static",
"function",
"prompt",
"(",
"$",
"prompt",
"=",
"''",
",",
"$",
"trim",
"=",
"true",
")",
"{",
"$",
"prompt",
"&&",
"self",
"::",
"lineOut",
"(",
"$",
"prompt",
")",
";",
"self",
"::",
"lineOut",
"(",
"'> '",
",",
"null",
",",
... | Receive input from the commandline.
@param string $prompt Something to say to the user indicating your waiting for a response
@param bool $trim Wether to trim the response
@return string The user's response | [
"Receive",
"input",
"from",
"the",
"commandline",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli.php#L107-L116 | train |
grrr-amsterdam/garp3 | library/Garp/Cli.php | Garp_Cli.confirm | public static function confirm($msg) {
print $msg . ' > ';
system('stty -icanon');
$handle = fopen('php://stdin', 'r');
$char = fgetc($handle);
system('stty icanon');
print "\n";
$allowedResponses = array('y', 'Y', 'n', 'N');
if (!in_array($char, $allowedResponses)) {
// nag 'em some more
Garp_Cli::errorOut('Please respond with a clear y or n');
return static::confirm($msg);
}
return $char === 'y' || $char === 'Y';
} | php | public static function confirm($msg) {
print $msg . ' > ';
system('stty -icanon');
$handle = fopen('php://stdin', 'r');
$char = fgetc($handle);
system('stty icanon');
print "\n";
$allowedResponses = array('y', 'Y', 'n', 'N');
if (!in_array($char, $allowedResponses)) {
// nag 'em some more
Garp_Cli::errorOut('Please respond with a clear y or n');
return static::confirm($msg);
}
return $char === 'y' || $char === 'Y';
} | [
"public",
"static",
"function",
"confirm",
"(",
"$",
"msg",
")",
"{",
"print",
"$",
"msg",
".",
"' > '",
";",
"system",
"(",
"'stty -icanon'",
")",
";",
"$",
"handle",
"=",
"fopen",
"(",
"'php://stdin'",
",",
"'r'",
")",
";",
"$",
"char",
"=",
"fgetc... | Force user to confirm a question with yes or no.
@param string $msg Question or message to display. A prompt (>) will be added.
@return bool Returns true if answer was 'y' or 'Y', no enter needed. | [
"Force",
"user",
"to",
"confirm",
"a",
"question",
"with",
"yes",
"or",
"no",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli.php#L124-L139 | train |
grrr-amsterdam/garp3 | library/Garp/Cli.php | Garp_Cli.makeHttpCall | public static function makeHttpCall($uri) {
$request = new Zend_Controller_Request_Http();
$request->setRequestUri($uri);
$application = Zend_Registry::get('application');
$front = $application->getBootstrap()->getResource('FrontController');
$default = $front->getDefaultModule();
if (null === $front->getControllerDirectory($default)) {
throw new Zend_Application_Bootstrap_Exception(
'No default controller directory registered with front controller'
);
}
$front->setParam('bootstrap', $application->getBootstrap());
// Make sure we aren't blocked from the ContentController as per the rules in the ACL
$front->unregisterPlugin('Garp_Controller_Plugin_Auth');
// Make sure no output is rendered
$front->returnResponse(true);
$response = $front->dispatch($request);
return $response;
} | php | public static function makeHttpCall($uri) {
$request = new Zend_Controller_Request_Http();
$request->setRequestUri($uri);
$application = Zend_Registry::get('application');
$front = $application->getBootstrap()->getResource('FrontController');
$default = $front->getDefaultModule();
if (null === $front->getControllerDirectory($default)) {
throw new Zend_Application_Bootstrap_Exception(
'No default controller directory registered with front controller'
);
}
$front->setParam('bootstrap', $application->getBootstrap());
// Make sure we aren't blocked from the ContentController as per the rules in the ACL
$front->unregisterPlugin('Garp_Controller_Plugin_Auth');
// Make sure no output is rendered
$front->returnResponse(true);
$response = $front->dispatch($request);
return $response;
} | [
"public",
"static",
"function",
"makeHttpCall",
"(",
"$",
"uri",
")",
"{",
"$",
"request",
"=",
"new",
"Zend_Controller_Request_Http",
"(",
")",
";",
"$",
"request",
"->",
"setRequestUri",
"(",
"$",
"uri",
")",
";",
"$",
"application",
"=",
"Zend_Registry",
... | For some functionality you absolutely need an HTTP context.
This method mimics a standard Zend request.
@param string $uri
@return string The response body | [
"For",
"some",
"functionality",
"you",
"absolutely",
"need",
"an",
"HTTP",
"context",
".",
"This",
"method",
"mimics",
"a",
"standard",
"Zend",
"request",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli.php#L260-L279 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Cdn.php | Garp_Cli_Command_Cdn._gatherConfigVars | protected function _gatherConfigVars() {
$source = $this->_stdin ?
$this->_parseStdin($this->_stdin) :
Zend_Registry::get('config')->toArray();
$cdnConfig = f\prop('cdn', $source);
$s3Config = f\prop('s3', $cdnConfig);
return array(
'apikey' => f\prop('apikey', $s3Config),
'secret' => f\prop('secret', $s3Config),
'bucket' => f\prop('bucket', $s3Config),
'region' => f\prop('region', $s3Config),
'readonly' => f\prop('readonly', $cdnConfig),
'gzip' => f\prop('gzip', $cdnConfig),
'gzip_exceptions' => f\prop('gzip_exceptions', $cdnConfig)
);
} | php | protected function _gatherConfigVars() {
$source = $this->_stdin ?
$this->_parseStdin($this->_stdin) :
Zend_Registry::get('config')->toArray();
$cdnConfig = f\prop('cdn', $source);
$s3Config = f\prop('s3', $cdnConfig);
return array(
'apikey' => f\prop('apikey', $s3Config),
'secret' => f\prop('secret', $s3Config),
'bucket' => f\prop('bucket', $s3Config),
'region' => f\prop('region', $s3Config),
'readonly' => f\prop('readonly', $cdnConfig),
'gzip' => f\prop('gzip', $cdnConfig),
'gzip_exceptions' => f\prop('gzip_exceptions', $cdnConfig)
);
} | [
"protected",
"function",
"_gatherConfigVars",
"(",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"_stdin",
"?",
"$",
"this",
"->",
"_parseStdin",
"(",
"$",
"this",
"->",
"_stdin",
")",
":",
"Zend_Registry",
"::",
"get",
"(",
"'config'",
")",
"->",
"... | Take the required variables necessary for distributing assets.
@return array | [
"Take",
"the",
"required",
"variables",
"necessary",
"for",
"distributing",
"assets",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Cdn.php#L128-L143 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Cdn.php | Garp_Cli_Command_Cdn._parseStdin | protected function _parseStdin($stdin) {
try {
$values = Zend_Json::decode($stdin);
// Switch ENV vars to the given values.
$currentEnv = $this->_updateEnvVars($values);
// Note: we use "production" here because it's the highest level a config file can
// support, making sure all required parameters are probably present.
// Actual credentials will be provided from ENV.
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/assets.ini', 'production');
// Reset ENV vars.
$this->_updateEnvVars($currentEnv);
return $config->toArray();
} catch (Zend_Json_Exception $e) {
throw new Exception(
'Data passed thru STDIN needs to be in JSON-format'
);
}
} | php | protected function _parseStdin($stdin) {
try {
$values = Zend_Json::decode($stdin);
// Switch ENV vars to the given values.
$currentEnv = $this->_updateEnvVars($values);
// Note: we use "production" here because it's the highest level a config file can
// support, making sure all required parameters are probably present.
// Actual credentials will be provided from ENV.
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/assets.ini', 'production');
// Reset ENV vars.
$this->_updateEnvVars($currentEnv);
return $config->toArray();
} catch (Zend_Json_Exception $e) {
throw new Exception(
'Data passed thru STDIN needs to be in JSON-format'
);
}
} | [
"protected",
"function",
"_parseStdin",
"(",
"$",
"stdin",
")",
"{",
"try",
"{",
"$",
"values",
"=",
"Zend_Json",
"::",
"decode",
"(",
"$",
"stdin",
")",
";",
"// Switch ENV vars to the given values.",
"$",
"currentEnv",
"=",
"$",
"this",
"->",
"_updateEnvVars... | Parse STDIN as JSON.
Output is formatted like the standard assets.ini.
@param string $stdin
@return array | [
"Parse",
"STDIN",
"as",
"JSON",
".",
"Output",
"is",
"formatted",
"like",
"the",
"standard",
"assets",
".",
"ini",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Cdn.php#L152-L169 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Cdn.php | Garp_Cli_Command_Cdn._updateEnvVars | protected function _updateEnvVars(array $vars) {
return f\reduce_assoc(
function ($o, $var, $key) {
// Store the current value
$o[$key] = getenv($key);
// Put the new value
putenv("{$key}={$var}");
return $o;
},
array(),
$vars
);
} | php | protected function _updateEnvVars(array $vars) {
return f\reduce_assoc(
function ($o, $var, $key) {
// Store the current value
$o[$key] = getenv($key);
// Put the new value
putenv("{$key}={$var}");
return $o;
},
array(),
$vars
);
} | [
"protected",
"function",
"_updateEnvVars",
"(",
"array",
"$",
"vars",
")",
"{",
"return",
"f",
"\\",
"reduce_assoc",
"(",
"function",
"(",
"$",
"o",
",",
"$",
"var",
",",
"$",
"key",
")",
"{",
"// Store the current value",
"$",
"o",
"[",
"$",
"key",
"]... | Update ENV vars with the given values.
Returns the _current_ values.
@param array $vars The new values
@return array The old values | [
"Update",
"ENV",
"vars",
"with",
"the",
"given",
"values",
".",
"Returns",
"the",
"_current_",
"values",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Cdn.php#L178-L190 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Vimeoable.php | Garp_Model_Behavior_Vimeoable._fillFields | protected function _fillFields(array $input) {
$sourceApiKey = $this->_useVimeoPro ? 'advanced' : 'simple';
if (!array_key_exists($this->_fields[$sourceApiKey]['url'], $input)) {
throw new Garp_Model_Behavior_Exception(
sprintf(self::EXCEPTION_MISSING_FIELD, $this->_fields['url'])
);
}
$url = $input[$this->_fields[$sourceApiKey]['url']];
if (empty($url)) {
return $input;
}
$videoData = $this->_getVideo($url);
if (!$videoData) {
throw new Garp_Model_Behavior_Exception(sprintf(self::EXCEPTION_VIDEO_NOT_FOUND, $url));
}
$out = array();
$source = $this->_fields[$sourceApiKey];
foreach ($source as $vimeoKey => $garpKey) {
$this->_addDataKey($out, $input, $videoData, $vimeoKey, $garpKey);
}
// if embedding is not allowed, hack our way around it.
if (empty($out['player'])) {
$out['player'] = 'https://player.vimeo.com/video/' . $videoData['id'];
}
return $out;
} | php | protected function _fillFields(array $input) {
$sourceApiKey = $this->_useVimeoPro ? 'advanced' : 'simple';
if (!array_key_exists($this->_fields[$sourceApiKey]['url'], $input)) {
throw new Garp_Model_Behavior_Exception(
sprintf(self::EXCEPTION_MISSING_FIELD, $this->_fields['url'])
);
}
$url = $input[$this->_fields[$sourceApiKey]['url']];
if (empty($url)) {
return $input;
}
$videoData = $this->_getVideo($url);
if (!$videoData) {
throw new Garp_Model_Behavior_Exception(sprintf(self::EXCEPTION_VIDEO_NOT_FOUND, $url));
}
$out = array();
$source = $this->_fields[$sourceApiKey];
foreach ($source as $vimeoKey => $garpKey) {
$this->_addDataKey($out, $input, $videoData, $vimeoKey, $garpKey);
}
// if embedding is not allowed, hack our way around it.
if (empty($out['player'])) {
$out['player'] = 'https://player.vimeo.com/video/' . $videoData['id'];
}
return $out;
} | [
"protected",
"function",
"_fillFields",
"(",
"array",
"$",
"input",
")",
"{",
"$",
"sourceApiKey",
"=",
"$",
"this",
"->",
"_useVimeoPro",
"?",
"'advanced'",
":",
"'simple'",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"_fields",
"[",
... | Retrieves additional data about the video corresponding with given input url from Vimeo,
or video id, and returns new data structure.
@param array $input New data
@return array | [
"Retrieves",
"additional",
"data",
"about",
"the",
"video",
"corresponding",
"with",
"given",
"input",
"url",
"from",
"Vimeo",
"or",
"video",
"id",
"and",
"returns",
"new",
"data",
"structure",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Vimeoable.php#L110-L138 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Vimeoable.php | Garp_Model_Behavior_Vimeoable._addDataKey | protected function _addDataKey(&$output, $input, $videoData, $vimeoKey, $garpKey) {
// Note, the advanced API does not return a URL field, so pick it from the $input instead.
if ($vimeoKey == 'url' && $this->_useVimeoPro) {
$output[$garpKey] = $input[$garpKey];
return;
}
$value = $this->_extractValue($videoData, $vimeoKey);
// allow overwriting of fields
if (!empty($input[$garpKey]) && $this->_valueMaybeOverwritten($garpKey)) {
$value = $input[$garpKey];
}
$this->_populateOutput($output, $garpKey, $value);
} | php | protected function _addDataKey(&$output, $input, $videoData, $vimeoKey, $garpKey) {
// Note, the advanced API does not return a URL field, so pick it from the $input instead.
if ($vimeoKey == 'url' && $this->_useVimeoPro) {
$output[$garpKey] = $input[$garpKey];
return;
}
$value = $this->_extractValue($videoData, $vimeoKey);
// allow overwriting of fields
if (!empty($input[$garpKey]) && $this->_valueMaybeOverwritten($garpKey)) {
$value = $input[$garpKey];
}
$this->_populateOutput($output, $garpKey, $value);
} | [
"protected",
"function",
"_addDataKey",
"(",
"&",
"$",
"output",
",",
"$",
"input",
",",
"$",
"videoData",
",",
"$",
"vimeoKey",
",",
"$",
"garpKey",
")",
"{",
"// Note, the advanced API does not return a URL field, so pick it from the $input instead.",
"if",
"(",
"$"... | Populate data with Vimeo data
@param array $output The array to populate
@param array $input The input given from the insert/update call
@param array $videoData Video data retrieved from Vimeo
@param string $vimeoKey Key used by Vimeo
@param string $garpKey Key used by Garp
@return void | [
"Populate",
"data",
"with",
"Vimeo",
"data"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Vimeoable.php#L150-L165 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Vimeoable.php | Garp_Model_Behavior_Vimeoable._extractValue | protected function _extractValue(array $videoData, $key) {
// Allow dot-notation to walk thru arrays
if (strpos($key, '.') === false) {
return $videoData[$key];
}
$keyParts = explode('.', $key);
$key = current($keyParts);
$value = $videoData;
while (is_array($value) && array_key_exists($key, $value)) {
$value = $value[$key];
$key = next($keyParts);
}
if (is_array($value)) {
throw new Garp_Model_Behavior_Exception(
sprintf(self::EXCEPTION_UNDEFINED_MAPPING, $key)
);
}
return $value;
} | php | protected function _extractValue(array $videoData, $key) {
// Allow dot-notation to walk thru arrays
if (strpos($key, '.') === false) {
return $videoData[$key];
}
$keyParts = explode('.', $key);
$key = current($keyParts);
$value = $videoData;
while (is_array($value) && array_key_exists($key, $value)) {
$value = $value[$key];
$key = next($keyParts);
}
if (is_array($value)) {
throw new Garp_Model_Behavior_Exception(
sprintf(self::EXCEPTION_UNDEFINED_MAPPING, $key)
);
}
return $value;
} | [
"protected",
"function",
"_extractValue",
"(",
"array",
"$",
"videoData",
",",
"$",
"key",
")",
"{",
"// Allow dot-notation to walk thru arrays",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"return",
"$",
"videoData",
"["... | Extract value from Vimeo video data
@param array $videoData
@param string $key
@return string | [
"Extract",
"value",
"from",
"Vimeo",
"video",
"data"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Vimeoable.php#L174-L192 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Vimeoable.php | Garp_Model_Behavior_Vimeoable._getVideo | protected function _getVideo($url) {
return $this->_useVimeoPro ? $this->_getProVideo($url) : $this->_getRegularVideo($url);
} | php | protected function _getVideo($url) {
return $this->_useVimeoPro ? $this->_getProVideo($url) : $this->_getRegularVideo($url);
} | [
"protected",
"function",
"_getVideo",
"(",
"$",
"url",
")",
"{",
"return",
"$",
"this",
"->",
"_useVimeoPro",
"?",
"$",
"this",
"->",
"_getProVideo",
"(",
"$",
"url",
")",
":",
"$",
"this",
"->",
"_getRegularVideo",
"(",
"$",
"url",
")",
";",
"}"
] | Retrieve Vimeo video
@param string $url Vimeo url
@return array | [
"Retrieve",
"Vimeo",
"video"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Vimeoable.php#L217-L219 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Vimeoable.php | Garp_Model_Behavior_Vimeoable._getProVideo | protected function _getProVideo($url) {
$vimeoVars = $this->_getVimeoConfig();
$vimeo = new Garp_Service_Vimeo_Pro($vimeoVars->consumerKey, $vimeoVars->consumerSecret);
$this->_setVimeoAccessToken($vimeo);
// check if a Vimeo URL is given
$pattern = '~vimeo.com/(?:video/)?([0-9]+)~';
preg_match($pattern, $url, $matches);
if (!isset($matches[1])) {
throw new Garp_Model_Behavior_Exception(self::EXCEPTION_MISSING_VIMEO_ID);
}
$videoId = $matches[1];
$video = $vimeo->videos->getInfo($videoId);
return $video[0];
} | php | protected function _getProVideo($url) {
$vimeoVars = $this->_getVimeoConfig();
$vimeo = new Garp_Service_Vimeo_Pro($vimeoVars->consumerKey, $vimeoVars->consumerSecret);
$this->_setVimeoAccessToken($vimeo);
// check if a Vimeo URL is given
$pattern = '~vimeo.com/(?:video/)?([0-9]+)~';
preg_match($pattern, $url, $matches);
if (!isset($matches[1])) {
throw new Garp_Model_Behavior_Exception(self::EXCEPTION_MISSING_VIMEO_ID);
}
$videoId = $matches[1];
$video = $vimeo->videos->getInfo($videoId);
return $video[0];
} | [
"protected",
"function",
"_getProVideo",
"(",
"$",
"url",
")",
"{",
"$",
"vimeoVars",
"=",
"$",
"this",
"->",
"_getVimeoConfig",
"(",
")",
";",
"$",
"vimeo",
"=",
"new",
"Garp_Service_Vimeo_Pro",
"(",
"$",
"vimeoVars",
"->",
"consumerKey",
",",
"$",
"vimeo... | Retrieve Vimeo video from the Pro API
@param string $url Vimeo url
@return array | [
"Retrieve",
"Vimeo",
"video",
"from",
"the",
"Pro",
"API"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Vimeoable.php#L227-L241 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Vimeoable.php | Garp_Model_Behavior_Vimeoable._setVimeoAccessToken | protected function _setVimeoAccessToken(Garp_Service_Vimeo_Pro $vimeo) {
/**
* See if the currently logged in user has Vimeo credentials related to her,
* and use the token and token secret.
* That way a user can fetch private videos thru the API.
*/
$garpAuth = Garp_Auth::getInstance();
if (!$garpAuth->isLoggedIn()) {
return;
}
$currentUser = $garpAuth->getUserData();
$authVimeoModel = new Model_AuthVimeo();
$authVimeoRecord = $authVimeoModel->fetchRow(
$authVimeoModel->select()->where('user_id = ?', $currentUser['id'])
);
if ($authVimeoRecord) {
$vimeo->setAccessToken($authVimeoRecord->access_token);
$vimeo->setAccessTokenSecret($authVimeoRecord->access_token_secret);
}
} | php | protected function _setVimeoAccessToken(Garp_Service_Vimeo_Pro $vimeo) {
/**
* See if the currently logged in user has Vimeo credentials related to her,
* and use the token and token secret.
* That way a user can fetch private videos thru the API.
*/
$garpAuth = Garp_Auth::getInstance();
if (!$garpAuth->isLoggedIn()) {
return;
}
$currentUser = $garpAuth->getUserData();
$authVimeoModel = new Model_AuthVimeo();
$authVimeoRecord = $authVimeoModel->fetchRow(
$authVimeoModel->select()->where('user_id = ?', $currentUser['id'])
);
if ($authVimeoRecord) {
$vimeo->setAccessToken($authVimeoRecord->access_token);
$vimeo->setAccessTokenSecret($authVimeoRecord->access_token_secret);
}
} | [
"protected",
"function",
"_setVimeoAccessToken",
"(",
"Garp_Service_Vimeo_Pro",
"$",
"vimeo",
")",
"{",
"/**\n * See if the currently logged in user has Vimeo credentials related to her,\n * and use the token and token secret.\n * That way a user can fetch private videos th... | Set Vimeo access token
@param Garp_Service_Vimeo_Pro $vimeo
@return void | [
"Set",
"Vimeo",
"access",
"token"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Vimeoable.php#L249-L268 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Vimeo.php | Garp_Service_Vimeo.user | public function user($username, $request) {
$options = array(
'info', 'videos', 'likes', 'appears_in',
'all_videos', 'subscriptions', 'albums',
'channels', 'groups', 'contacts_videos',
'contacts_like'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. vailable options are ' . implode(', ', $options)
);
}
return $this->request($username . '/' . $request);
} | php | public function user($username, $request) {
$options = array(
'info', 'videos', 'likes', 'appears_in',
'all_videos', 'subscriptions', 'albums',
'channels', 'groups', 'contacts_videos',
'contacts_like'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. vailable options are ' . implode(', ', $options)
);
}
return $this->request($username . '/' . $request);
} | [
"public",
"function",
"user",
"(",
"$",
"username",
",",
"$",
"request",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'info'",
",",
"'videos'",
",",
"'likes'",
",",
"'appears_in'",
",",
"'all_videos'",
",",
"'subscriptions'",
",",
"'albums'",
",",
"'chann... | Make a User request
@param String $username
@param String $request
@return Array | [
"Make",
"a",
"User",
"request"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Vimeo.php#L26-L39 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Vimeo.php | Garp_Service_Vimeo.video | public function video($videoId) {
// check if a Vimeo URL is given
$pattern = '~vimeo.com/(?:video/)?([0-9]+)~';
if (preg_match($pattern, $videoId, $matches)) {
$videoId = $matches[1];
}
return $this->request('video/' . $videoId);
} | php | public function video($videoId) {
// check if a Vimeo URL is given
$pattern = '~vimeo.com/(?:video/)?([0-9]+)~';
if (preg_match($pattern, $videoId, $matches)) {
$videoId = $matches[1];
}
return $this->request('video/' . $videoId);
} | [
"public",
"function",
"video",
"(",
"$",
"videoId",
")",
"{",
"// check if a Vimeo URL is given",
"$",
"pattern",
"=",
"'~vimeo.com/(?:video/)?([0-9]+)~'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"videoId",
",",
"$",
"matches",
")",
")",
"... | Make a Video request
@param String $videoId Video id or Vimeo URL
@return Array | [
"Make",
"a",
"Video",
"request"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Vimeo.php#L48-L55 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Vimeo.php | Garp_Service_Vimeo.activity | public function activity($username, $request) {
$options = array(
'user_did', 'happened_to_user', 'contacts_did', 'happened_to_contacts', 'everyone_did'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. Available options are ' . implode(', ', $options)
);
}
return $this->request('activity/' . $username . '/' . $request);
} | php | public function activity($username, $request) {
$options = array(
'user_did', 'happened_to_user', 'contacts_did', 'happened_to_contacts', 'everyone_did'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. Available options are ' . implode(', ', $options)
);
}
return $this->request('activity/' . $username . '/' . $request);
} | [
"public",
"function",
"activity",
"(",
"$",
"username",
",",
"$",
"request",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'user_did'",
",",
"'happened_to_user'",
",",
"'contacts_did'",
",",
"'happened_to_contacts'",
",",
"'everyone_did'",
")",
";",
"if",
"(",... | Make an Activity request
@param String $username
@param String $request
@return Array | [
"Make",
"an",
"Activity",
"request"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Vimeo.php#L65-L75 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Vimeo.php | Garp_Service_Vimeo.group | public function group($groupname, $request) {
$options = array(
'videos', 'users', 'info'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. Available options are ' . implode(', ', $options)
);
}
return $this->request('group/' . $groupname . '/' . $request);
} | php | public function group($groupname, $request) {
$options = array(
'videos', 'users', 'info'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. Available options are ' . implode(', ', $options)
);
}
return $this->request('group/' . $groupname . '/' . $request);
} | [
"public",
"function",
"group",
"(",
"$",
"groupname",
",",
"$",
"request",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'videos'",
",",
"'users'",
",",
"'info'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"request",
",",
"$",
"options",
")",
... | Make a Group request
@param String $groupname
@param String $request
@return Array | [
"Make",
"a",
"Group",
"request"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Vimeo.php#L85-L95 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Vimeo.php | Garp_Service_Vimeo.channel | public function channel($channel, $request) {
$options = array(
'videos', 'info'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. Available options are ' . implode(', ', $options)
);
}
return $this->request('channel/' . $channel . '/' . $request);
} | php | public function channel($channel, $request) {
$options = array(
'videos', 'info'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. Available options are ' . implode(', ', $options)
);
}
return $this->request('channel/' . $channel . '/' . $request);
} | [
"public",
"function",
"channel",
"(",
"$",
"channel",
",",
"$",
"request",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'videos'",
",",
"'info'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"request",
",",
"$",
"options",
")",
")",
"{",
"throw... | Make a Channel request
@param String $channel
@param String $request
@return Array | [
"Make",
"a",
"Channel",
"request"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Vimeo.php#L105-L115 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Vimeo.php | Garp_Service_Vimeo.album | public function album($albumId, $request) {
$options = array(
'videos', 'info'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. Available options are ' . implode(', ', $options)
);
}
return $this->request('album/' . $albumId . '/' . $request);
} | php | public function album($albumId, $request) {
$options = array(
'videos', 'info'
);
if (!in_array($request, $options)) {
throw new Garp_Service_Vimeo_Exception(
'Invalid request. Available options are ' . implode(', ', $options)
);
}
return $this->request('album/' . $albumId . '/' . $request);
} | [
"public",
"function",
"album",
"(",
"$",
"albumId",
",",
"$",
"request",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'videos'",
",",
"'info'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"request",
",",
"$",
"options",
")",
")",
"{",
"throw",... | Make a Album request
@param Int $albumId
@param String $request
@return Array | [
"Make",
"a",
"Album",
"request"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Vimeo.php#L125-L135 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Elasticsearchable.php | Garp_Model_Behavior_Elasticsearchable.afterUpdate | public function afterUpdate(&$args) {
$model = $args[0];
$where = $args[3];
$primaryKey = $model->extractPrimaryKey($where);
$id = $primaryKey['id'];
$this->afterSave($model, $id);
} | php | public function afterUpdate(&$args) {
$model = $args[0];
$where = $args[3];
$primaryKey = $model->extractPrimaryKey($where);
$id = $primaryKey['id'];
$this->afterSave($model, $id);
} | [
"public",
"function",
"afterUpdate",
"(",
"&",
"$",
"args",
")",
"{",
"$",
"model",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"where",
"=",
"$",
"args",
"[",
"3",
"]",
";",
"$",
"primaryKey",
"=",
"$",
"model",
"->",
"extractPrimaryKey",
"(",
"$... | AfterUpdate event listener.
@param Array $args Event listener parameters
@return Void | [
"AfterUpdate",
"event",
"listener",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Elasticsearchable.php#L83-L91 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Elasticsearchable.php | Garp_Model_Behavior_Elasticsearchable.afterSave | public function afterSave(Garp_Model_Db $model, $primaryKey) {
if (is_array($primaryKey)) {
throw new Exception(self::ERROR_PRIMARY_KEY_CANNOT_BE_ARRAY);
}
$boundModel = new Garp_Service_Elasticsearch_Db_BoundModel($model);
$row = $boundModel->fetchRow($primaryKey);
if (!$row) {
/* This is not supposed to happen,
but due to concurrency it theoretically might. */
return;
}
if (!$this->getRootable()) {
/* This record should not appear directly in the index,
* but only as related records.
*/
return;
}
$rowFilter = new Garp_Service_Elasticsearch_Db_RowFilter($model);
$columns = $this->getColumns();
$filteredRow = $rowFilter->filter($row, $columns);
$elasticModel = $this->_getElasticModel($model);
$pkMash = $this->_mashPrimaryKey($primaryKey);
$filteredRow['id'] = $pkMash;
$elasticModel->save($filteredRow);
} | php | public function afterSave(Garp_Model_Db $model, $primaryKey) {
if (is_array($primaryKey)) {
throw new Exception(self::ERROR_PRIMARY_KEY_CANNOT_BE_ARRAY);
}
$boundModel = new Garp_Service_Elasticsearch_Db_BoundModel($model);
$row = $boundModel->fetchRow($primaryKey);
if (!$row) {
/* This is not supposed to happen,
but due to concurrency it theoretically might. */
return;
}
if (!$this->getRootable()) {
/* This record should not appear directly in the index,
* but only as related records.
*/
return;
}
$rowFilter = new Garp_Service_Elasticsearch_Db_RowFilter($model);
$columns = $this->getColumns();
$filteredRow = $rowFilter->filter($row, $columns);
$elasticModel = $this->_getElasticModel($model);
$pkMash = $this->_mashPrimaryKey($primaryKey);
$filteredRow['id'] = $pkMash;
$elasticModel->save($filteredRow);
} | [
"public",
"function",
"afterSave",
"(",
"Garp_Model_Db",
"$",
"model",
",",
"$",
"primaryKey",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"primaryKey",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"self",
"::",
"ERROR_PRIMARY_KEY_CANNOT_BE_ARRAY",
")",
"... | Generic method for pushing a database row to the indexer.
@param Garp_Model_Db $model
@param int $primaryKey | [
"Generic",
"method",
"for",
"pushing",
"a",
"database",
"row",
"to",
"the",
"indexer",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Elasticsearchable.php#L98-L128 | train |
grrr-amsterdam/garp3 | application/modules/g/views/helpers/FileSize.php | G_View_Helper_FileSize.fileSize | public function fileSize($size) {
if (!$size) {
return '0 ' . $this->_sizes[0];
}
return round($size/pow(1024, ($i = floor(log($size, 1024)))), $i > 1 ? 2 : 0) .
' ' . $this->_sizes[$i];
} | php | public function fileSize($size) {
if (!$size) {
return '0 ' . $this->_sizes[0];
}
return round($size/pow(1024, ($i = floor(log($size, 1024)))), $i > 1 ? 2 : 0) .
' ' . $this->_sizes[$i];
} | [
"public",
"function",
"fileSize",
"(",
"$",
"size",
")",
"{",
"if",
"(",
"!",
"$",
"size",
")",
"{",
"return",
"'0 '",
".",
"$",
"this",
"->",
"_sizes",
"[",
"0",
"]",
";",
"}",
"return",
"round",
"(",
"$",
"size",
"/",
"pow",
"(",
"1024",
",",... | Format a filesize
@param int $size In bytes
@return string | [
"Format",
"a",
"filesize"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/FileSize.php#L23-L29 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Db/Image.php | Garp_Model_Db_Image.afterFetch | public function afterFetch(&$args) {
$results = &$args[1];
$scaler = new Garp_Image_Scaler();
$templateUrl = (string)$scaler->getScaledUrl('%d', '%s');
$templates = array_keys(Zend_Registry::get('config')->image->template->toArray());
$iterator = new Garp_Db_Table_Rowset_Iterator(
$results,
function ($result) use ($templates, $templateUrl) {
if (!isset($result->id)) {
return;
}
$result->setVirtual(
'urls',
array_reduce(
$templates,
function ($acc, $cur) use ($templateUrl, $result) {
$acc[$cur] = sprintf($templateUrl, $cur, $result->id);
return $acc;
},
array()
)
);
}
);
$iterator->walk();
} | php | public function afterFetch(&$args) {
$results = &$args[1];
$scaler = new Garp_Image_Scaler();
$templateUrl = (string)$scaler->getScaledUrl('%d', '%s');
$templates = array_keys(Zend_Registry::get('config')->image->template->toArray());
$iterator = new Garp_Db_Table_Rowset_Iterator(
$results,
function ($result) use ($templates, $templateUrl) {
if (!isset($result->id)) {
return;
}
$result->setVirtual(
'urls',
array_reduce(
$templates,
function ($acc, $cur) use ($templateUrl, $result) {
$acc[$cur] = sprintf($templateUrl, $cur, $result->id);
return $acc;
},
array()
)
);
}
);
$iterator->walk();
} | [
"public",
"function",
"afterFetch",
"(",
"&",
"$",
"args",
")",
"{",
"$",
"results",
"=",
"&",
"$",
"args",
"[",
"1",
"]",
";",
"$",
"scaler",
"=",
"new",
"Garp_Image_Scaler",
"(",
")",
";",
"$",
"templateUrl",
"=",
"(",
"string",
")",
"$",
"scaler... | Include preview URLs in the resultset
@param array $args
@return void | [
"Include",
"preview",
"URLs",
"in",
"the",
"resultset"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Image.php#L35-L60 | train |
grrr-amsterdam/garp3 | application/modules/g/views/helpers/YouTube.php | G_View_Helper_YouTube.render | public function render($youtube, array $options = array()) {
$this->_setDefaultAttribs($options);
$_attribs = $options['attribs'];
$_attribs['width'] = $options['width'];
$_attribs['height'] = $options['height'];
$_attribs['frameborder'] = '0';
$_attribs['allowfullscreen'] = 'allowfullscreen';
// unset the parameters that are not part of the query string
unset($options['width']);
unset($options['height']);
unset($options['attribs']);
// create the YouTube URL
$youtubeUrl = $this->getPlayerUrl($youtube, $options);
$_attribs['src'] = $youtubeUrl;
$html = '<iframe' . $this->_htmlAttribs($_attribs) . '></iframe>';
return $html;
} | php | public function render($youtube, array $options = array()) {
$this->_setDefaultAttribs($options);
$_attribs = $options['attribs'];
$_attribs['width'] = $options['width'];
$_attribs['height'] = $options['height'];
$_attribs['frameborder'] = '0';
$_attribs['allowfullscreen'] = 'allowfullscreen';
// unset the parameters that are not part of the query string
unset($options['width']);
unset($options['height']);
unset($options['attribs']);
// create the YouTube URL
$youtubeUrl = $this->getPlayerUrl($youtube, $options);
$_attribs['src'] = $youtubeUrl;
$html = '<iframe' . $this->_htmlAttribs($_attribs) . '></iframe>';
return $html;
} | [
"public",
"function",
"render",
"(",
"$",
"youtube",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_setDefaultAttribs",
"(",
"$",
"options",
")",
";",
"$",
"_attribs",
"=",
"$",
"options",
"[",
"'attribs'",
"]",
... | Render a youtube object tag.
@param Garp_Db_Table_Row|string $youtube A record from the `youtube_videos` table,
or a url to a YouTube video.
@param array $options Various rendering options
@return string | [
"Render",
"a",
"youtube",
"object",
"tag",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/YouTube.php#L34-L54 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/Config/Validator/Model/Abstract.php | Garp_Spawn_Config_Validator_Model_Abstract._validateUniqueKeyLength | protected function _validateUniqueKeyLength(ArrayObject $config) {
$restrictedFieldTypes = array('text', 'html');
if (array_key_exists('inputs', $config)) {
foreach ($config['inputs'] as $inputName => $input) {
if (
array_key_exists('unique', $input) &&
$input['unique'] &&
(
(
!array_key_exists('type', $input) &&
!Garp_Spawn_Util::stringEndsIn('email', $inputName) &&
!Garp_Spawn_Util::stringEndsIn('url', $inputName) &&
!Garp_Spawn_Util::stringEndsIn('id', $inputName) &&
!Garp_Spawn_Util::stringEndsIn('date', $inputName) &&
!Garp_Spawn_Util::stringEndsIn('time', $inputName)
) ||
(
array_key_exists('type', $input) &&
in_array($input['type'], $restrictedFieldTypes)
)
) &&
(
!array_key_exists('maxLength', $input) ||
$input['maxLength'] > 255
)
) {
throw new Exception("You've set {$config['id']}.{$inputName} to unique, but this type of field has to have a maxLength of 255 at most to be made unique.");
}
}
}
} | php | protected function _validateUniqueKeyLength(ArrayObject $config) {
$restrictedFieldTypes = array('text', 'html');
if (array_key_exists('inputs', $config)) {
foreach ($config['inputs'] as $inputName => $input) {
if (
array_key_exists('unique', $input) &&
$input['unique'] &&
(
(
!array_key_exists('type', $input) &&
!Garp_Spawn_Util::stringEndsIn('email', $inputName) &&
!Garp_Spawn_Util::stringEndsIn('url', $inputName) &&
!Garp_Spawn_Util::stringEndsIn('id', $inputName) &&
!Garp_Spawn_Util::stringEndsIn('date', $inputName) &&
!Garp_Spawn_Util::stringEndsIn('time', $inputName)
) ||
(
array_key_exists('type', $input) &&
in_array($input['type'], $restrictedFieldTypes)
)
) &&
(
!array_key_exists('maxLength', $input) ||
$input['maxLength'] > 255
)
) {
throw new Exception("You've set {$config['id']}.{$inputName} to unique, but this type of field has to have a maxLength of 255 at most to be made unique.");
}
}
}
} | [
"protected",
"function",
"_validateUniqueKeyLength",
"(",
"ArrayObject",
"$",
"config",
")",
"{",
"$",
"restrictedFieldTypes",
"=",
"array",
"(",
"'text'",
",",
"'html'",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'inputs'",
",",
"$",
"config",
")",
")",
... | Throw a warning when a field is set to unique, while its maxLength is too large. | [
"Throw",
"a",
"warning",
"when",
"a",
"field",
"is",
"set",
"to",
"unique",
"while",
"its",
"maxLength",
"is",
"too",
"large",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Config/Validator/Model/Abstract.php#L164-L195 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Authenticatable.php | Garp_Model_Behavior_Authenticatable.updateLoginStats | public function updateLoginStats($userId, $columns = array()) {
if (isset($_SERVER['REMOTE_ADDR'])) {
$columns['ip_address'] = $_SERVER['REMOTE_ADDR'];
}
$columns['last_login'] = new Zend_Db_Expr('NOW()');
return $this->_model->update(
$columns,
$this->_model->getAdapter()->quoteInto('user_id = ?', $userId)
);
} | php | public function updateLoginStats($userId, $columns = array()) {
if (isset($_SERVER['REMOTE_ADDR'])) {
$columns['ip_address'] = $_SERVER['REMOTE_ADDR'];
}
$columns['last_login'] = new Zend_Db_Expr('NOW()');
return $this->_model->update(
$columns,
$this->_model->getAdapter()->quoteInto('user_id = ?', $userId)
);
} | [
"public",
"function",
"updateLoginStats",
"(",
"$",
"userId",
",",
"$",
"columns",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
")",
"{",
"$",
"columns",
"[",
"'ip_address'",
"]",
"=",
"$"... | Update login statistics, like IP address and the current date
@param int $userId The user_id value
@param array $columns Extra columns, variable
@return int The number of rows updated. | [
"Update",
"login",
"statistics",
"like",
"IP",
"address",
"and",
"the",
"current",
"date"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Authenticatable.php#L22-L31 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Db.php | Garp_Cli_Command_Db.connect | public function connect() {
$adapter = Zend_Db_Table::getDefaultAdapter();
if (!$adapter) {
Garp_Cli::errorOut('No database adapter found');
return false;
}
$config = $adapter->getConfig();
$params = array(
'-u' . escapeshellarg($config['username']),
'-p' . escapeshellarg($config['password']),
'-h' . escapeshellarg($config['host']),
' ' . escapeshellarg($config['dbname'])
);
$cmd = 'mysql ' . implode(' ', $params);
$process = proc_open($cmd, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes);
$proc_status = proc_get_status($process);
$exit_code = proc_close($process);
return ($proc_status["running"] ? $exit_code : $proc_status["exitcode"] ) == 0;
} | php | public function connect() {
$adapter = Zend_Db_Table::getDefaultAdapter();
if (!$adapter) {
Garp_Cli::errorOut('No database adapter found');
return false;
}
$config = $adapter->getConfig();
$params = array(
'-u' . escapeshellarg($config['username']),
'-p' . escapeshellarg($config['password']),
'-h' . escapeshellarg($config['host']),
' ' . escapeshellarg($config['dbname'])
);
$cmd = 'mysql ' . implode(' ', $params);
$process = proc_open($cmd, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes);
$proc_status = proc_get_status($process);
$exit_code = proc_close($process);
return ($proc_status["running"] ? $exit_code : $proc_status["exitcode"] ) == 0;
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"$",
"adapter",
"=",
"Zend_Db_Table",
"::",
"getDefaultAdapter",
"(",
")",
";",
"if",
"(",
"!",
"$",
"adapter",
")",
"{",
"Garp_Cli",
"::",
"errorOut",
"(",
"'No database adapter found'",
")",
";",
"return",
... | Start the interactive mysql client
@return bool | [
"Start",
"the",
"interactive",
"mysql",
"client"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Db.php#L68-L86 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Db.php | Garp_Cli_Command_Db._getTextualColumns | protected function _getTextualColumns(Garp_Model_Db $model) {
$columns = $model->info(Zend_Db_Table::METADATA);
$textTypes = array('varchar', 'text', 'mediumtext', 'longtext', 'tinytext');
foreach ($columns as $column => $meta) {
if (!in_array($meta['DATA_TYPE'], $textTypes)) {
unset($columns[$column]);
}
}
return array_keys($columns);
} | php | protected function _getTextualColumns(Garp_Model_Db $model) {
$columns = $model->info(Zend_Db_Table::METADATA);
$textTypes = array('varchar', 'text', 'mediumtext', 'longtext', 'tinytext');
foreach ($columns as $column => $meta) {
if (!in_array($meta['DATA_TYPE'], $textTypes)) {
unset($columns[$column]);
}
}
return array_keys($columns);
} | [
"protected",
"function",
"_getTextualColumns",
"(",
"Garp_Model_Db",
"$",
"model",
")",
"{",
"$",
"columns",
"=",
"$",
"model",
"->",
"info",
"(",
"Zend_Db_Table",
"::",
"METADATA",
")",
";",
"$",
"textTypes",
"=",
"array",
"(",
"'varchar'",
",",
"'text'",
... | Get all textual columns from a table
@param Garp_Model_Db $model The model
@return array | [
"Get",
"all",
"textual",
"columns",
"from",
"a",
"table"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Db.php#L150-L159 | train |
PhpGt/WebEngine | src/Route/Router.php | Router.getViewLogicSubPath | protected function getViewLogicSubPath(string $uriPath):string {
$uriPath = str_replace(
"/",
DIRECTORY_SEPARATOR,
$uriPath
);
$baseViewLogicPath = $this->getBaseViewLogicPath();
$absolutePath = $baseViewLogicPath . $uriPath;
$relativePath = substr($absolutePath, strlen($baseViewLogicPath));
if(strlen($relativePath) > 1) {
$relativePath = rtrim($relativePath, DIRECTORY_SEPARATOR);
}
return $relativePath;
} | php | protected function getViewLogicSubPath(string $uriPath):string {
$uriPath = str_replace(
"/",
DIRECTORY_SEPARATOR,
$uriPath
);
$baseViewLogicPath = $this->getBaseViewLogicPath();
$absolutePath = $baseViewLogicPath . $uriPath;
$relativePath = substr($absolutePath, strlen($baseViewLogicPath));
if(strlen($relativePath) > 1) {
$relativePath = rtrim($relativePath, DIRECTORY_SEPARATOR);
}
return $relativePath;
} | [
"protected",
"function",
"getViewLogicSubPath",
"(",
"string",
"$",
"uriPath",
")",
":",
"string",
"{",
"$",
"uriPath",
"=",
"str_replace",
"(",
"\"/\"",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"uriPath",
")",
";",
"$",
"baseViewLogicPath",
"=",
"$",
"this",
"... | The view-logic sub-path is the path on disk to the directory containing the requested
View and Logic files, relative to the base view-logic path. | [
"The",
"view",
"-",
"logic",
"sub",
"-",
"path",
"is",
"the",
"path",
"on",
"disk",
"to",
"the",
"directory",
"containing",
"the",
"requested",
"View",
"and",
"Logic",
"files",
"relative",
"to",
"the",
"base",
"view",
"-",
"logic",
"path",
"."
] | 2dc4010349c3c07a695b28e25ec0a8a44cb93ea2 | https://github.com/PhpGt/WebEngine/blob/2dc4010349c3c07a695b28e25ec0a8a44cb93ea2/src/Route/Router.php#L116-L130 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/Behavior/Factory.php | Garp_Spawn_Behavior_Factory.isI18nBehavior | public static function isI18nBehavior($name, $config, $inputs) {
if ($name === 'Sluggable') {
return self::_shouldSluggableBeSpawnedOnI18nModel($config, $inputs);
}
return true;
} | php | public static function isI18nBehavior($name, $config, $inputs) {
if ($name === 'Sluggable') {
return self::_shouldSluggableBeSpawnedOnI18nModel($config, $inputs);
}
return true;
} | [
"public",
"static",
"function",
"isI18nBehavior",
"(",
"$",
"name",
",",
"$",
"config",
",",
"$",
"inputs",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"'Sluggable'",
")",
"{",
"return",
"self",
"::",
"_shouldSluggableBeSpawnedOnI18nModel",
"(",
"$",
"config",
... | Check wether a behavior should be spawned on an i18n model.
This used to always be true, but could use better validation. For now we'll make do with
validation on the Sluggable behavior, that actually produces errors in some cases when
spawned on an i18n model erroneously. | [
"Check",
"wether",
"a",
"behavior",
"should",
"be",
"spawned",
"on",
"an",
"i18n",
"model",
".",
"This",
"used",
"to",
"always",
"be",
"true",
"but",
"could",
"use",
"better",
"validation",
".",
"For",
"now",
"we",
"ll",
"make",
"do",
"with",
"validation... | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Behavior/Factory.php#L32-L37 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Validator/Abstract.php | Garp_Model_Validator_Abstract.beforeInsert | public function beforeInsert(&$args) {
$model = &$args[0];
$data = &$args[1];
$this->validate($data, $model);
} | php | public function beforeInsert(&$args) {
$model = &$args[0];
$data = &$args[1];
$this->validate($data, $model);
} | [
"public",
"function",
"beforeInsert",
"(",
"&",
"$",
"args",
")",
"{",
"$",
"model",
"=",
"&",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"data",
"=",
"&",
"$",
"args",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"data",
",",
"$",... | BeforeInsert callback.
@param Array $args The new data is in $args[1]
@return Void | [
"BeforeInsert",
"callback",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Validator/Abstract.php#L28-L32 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Validator/Abstract.php | Garp_Model_Validator_Abstract.beforeUpdate | public function beforeUpdate(&$args) {
$model = &$args[0];
$data = &$args[1];
$where = &$args[2];
$this->validate($data, $model, true);
} | php | public function beforeUpdate(&$args) {
$model = &$args[0];
$data = &$args[1];
$where = &$args[2];
$this->validate($data, $model, true);
} | [
"public",
"function",
"beforeUpdate",
"(",
"&",
"$",
"args",
")",
"{",
"$",
"model",
"=",
"&",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"data",
"=",
"&",
"$",
"args",
"[",
"1",
"]",
";",
"$",
"where",
"=",
"&",
"$",
"args",
"[",
"2",
"]",
";",... | BeforeUpdate callback.
@param Array $args The new data is in $args[1]
@return Void | [
"BeforeUpdate",
"callback",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Validator/Abstract.php#L39-L44 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Slack.php | Garp_Service_Slack.postMessage | public function postMessage($text, $params = array()) {
$config = $this->getConfig();
$params['text'] = $text;
$params = $config->getParams($params);
return $this->_fsock_post(
$this->_constructWebhookUrl(),
$this->_constructParameters($params)
);
} | php | public function postMessage($text, $params = array()) {
$config = $this->getConfig();
$params['text'] = $text;
$params = $config->getParams($params);
return $this->_fsock_post(
$this->_constructWebhookUrl(),
$this->_constructParameters($params)
);
} | [
"public",
"function",
"postMessage",
"(",
"$",
"text",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"params",
"[",
"'text'",
"]",
"=",
"$",
"text",
";",
"$",
"params... | Post a message in a Slack channel.
@param $text Text to post in the Slack message
@param $params Extra, optional Slack parameters that
override the app-wide settings in app.ini,
that in turn override Slack's Incoming
Webhook settings.
f.i.:
'username' => 'me',
'icon_emoji' => ':ghost:',
'channel' => '#my-channel' | [
"Post",
"a",
"message",
"in",
"a",
"Slack",
"channel",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Slack.php#L47-L56 | train |
grrr-amsterdam/garp3 | application/modules/g/views/helpers/Html.php | G_View_Helper_Html.html | public function html($tag, $value = null, array $attributes = array()) {
// This happens when used from a Garp_Form context
if (array_key_exists('id', $attributes) && !$attributes['id']) {
unset($attributes['id']);
}
if (isset($attributes['tag'])) {
$tag = $attributes['tag'];
unset($attributes['tag']);
}
$escape = true;
if (array_key_exists('escape', $attributes)) {
$escape = $attributes['escape'];
unset($attributes['escape']);
}
$html = '<' . $tag;
$html .= $this->_htmlAttribs($attributes) . '>';
if ($value) {
if ($escape) {
$value = $this->view->escape($value);
}
$html .= $value;
}
$html .= '</' . $tag . '>';
return $html;
} | php | public function html($tag, $value = null, array $attributes = array()) {
// This happens when used from a Garp_Form context
if (array_key_exists('id', $attributes) && !$attributes['id']) {
unset($attributes['id']);
}
if (isset($attributes['tag'])) {
$tag = $attributes['tag'];
unset($attributes['tag']);
}
$escape = true;
if (array_key_exists('escape', $attributes)) {
$escape = $attributes['escape'];
unset($attributes['escape']);
}
$html = '<' . $tag;
$html .= $this->_htmlAttribs($attributes) . '>';
if ($value) {
if ($escape) {
$value = $this->view->escape($value);
}
$html .= $value;
}
$html .= '</' . $tag . '>';
return $html;
} | [
"public",
"function",
"html",
"(",
"$",
"tag",
",",
"$",
"value",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"// This happens when used from a Garp_Form context",
"if",
"(",
"array_key_exists",
"(",
"'id'",
",",
"$",
"att... | Render the HTML.
@param string $tag
@param string $value
@param array $attributes
@return string | [
"Render",
"the",
"HTML",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Html.php#L21-L46 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Spawn/Filter.php | Garp_Cli_Command_Spawn_Filter._getModuleFilter | protected function _getModuleFilter() {
$args = $this->getArgs();
$only = self::FILTER_MODULE_COMMAND;
if (!array_key_exists($only, $args)) {
return;
}
$filter = $args[$only];
return strtolower($filter);
} | php | protected function _getModuleFilter() {
$args = $this->getArgs();
$only = self::FILTER_MODULE_COMMAND;
if (!array_key_exists($only, $args)) {
return;
}
$filter = $args[$only];
return strtolower($filter);
} | [
"protected",
"function",
"_getModuleFilter",
"(",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"getArgs",
"(",
")",
";",
"$",
"only",
"=",
"self",
"::",
"FILTER_MODULE_COMMAND",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"only",
",",
"$",
"ar... | Returns the module that should be run, i.e. 'db' or 'files', or null if no filter is given.
@return string | [
"Returns",
"the",
"module",
"that",
"should",
"be",
"run",
"i",
".",
"e",
".",
"db",
"or",
"files",
"or",
"null",
"if",
"no",
"filter",
"is",
"given",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Spawn/Filter.php#L95-L105 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Slack.php | Garp_Cli_Command_Slack.send | public function send(array $args = array()) {
if (!$args || !array_key_exists(0, $args) || empty($args[0])) {
Garp_Cli::errorOut(self::ERROR_EMPTY_SEND);
return false;
}
$slack = new Garp_Service_Slack();
return $slack->postMessage($args[0]);
} | php | public function send(array $args = array()) {
if (!$args || !array_key_exists(0, $args) || empty($args[0])) {
Garp_Cli::errorOut(self::ERROR_EMPTY_SEND);
return false;
}
$slack = new Garp_Service_Slack();
return $slack->postMessage($args[0]);
} | [
"public",
"function",
"send",
"(",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"args",
"||",
"!",
"array_key_exists",
"(",
"0",
",",
"$",
"args",
")",
"||",
"empty",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
... | Post a message in a Slack channel
@param array $args
@return bool | [
"Post",
"a",
"message",
"in",
"a",
"Slack",
"channel"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Slack.php#L19-L27 | train |
grrr-amsterdam/garp3 | library/Garp/Auth/Adapter/Abstract.php | Garp_Auth_Adapter_Abstract._getAuthVars | protected function _getAuthVars() {
if (!$this->_configKey) {
throw new Garp_Auth_Exception('No config key found in '.__CLASS__.'::_configKey.');
}
$config = Zend_Registry::get('config');
if ($config->auth && $config->auth->adapters && $config->auth->adapters->{$this->_configKey}) {
return $config->auth->adapters->{$this->_configKey};
}
return null;
} | php | protected function _getAuthVars() {
if (!$this->_configKey) {
throw new Garp_Auth_Exception('No config key found in '.__CLASS__.'::_configKey.');
}
$config = Zend_Registry::get('config');
if ($config->auth && $config->auth->adapters && $config->auth->adapters->{$this->_configKey}) {
return $config->auth->adapters->{$this->_configKey};
}
return null;
} | [
"protected",
"function",
"_getAuthVars",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_configKey",
")",
"{",
"throw",
"new",
"Garp_Auth_Exception",
"(",
"'No config key found in '",
".",
"__CLASS__",
".",
"'::_configKey.'",
")",
";",
"}",
"$",
"config",
... | Get auth values related to this adapter
@return Zend_Config | [
"Get",
"auth",
"values",
"related",
"to",
"this",
"adapter"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Abstract.php#L80-L89 | train |
grrr-amsterdam/garp3 | library/Garp/Auth/Adapter/Abstract.php | Garp_Auth_Adapter_Abstract._mapProperties | protected function _mapProperties(array $props) {
$authVars = $this->_getAuthVars();
if ($authVars->mapperClass) {
$mapper = new $authVars->mapperClass();
if (!$mapper instanceof Garp_Auth_Adapter_Mapper_Abstract) {
throw new Garp_Auth_Adapter_Exception('Invalid property mapper specified: ' .
$authVars->mapperClass);
}
$cols = $mapper->map($props);
}
if ($authVars->mapping && !empty($authVars->mapping)) {
$cols = array();
foreach ($authVars->mapping as $mappedProp => $col) {
if ($col) {
$cols[$col] = !empty($props[$mappedProp]) ? $props[$mappedProp] : null;
}
}
} else {
throw new Garp_Auth_Exception('This authentication method requires '.
' a mapping of columns in application.ini.');
}
return array_merge($cols, $this->_extendedUserColumns);
} | php | protected function _mapProperties(array $props) {
$authVars = $this->_getAuthVars();
if ($authVars->mapperClass) {
$mapper = new $authVars->mapperClass();
if (!$mapper instanceof Garp_Auth_Adapter_Mapper_Abstract) {
throw new Garp_Auth_Adapter_Exception('Invalid property mapper specified: ' .
$authVars->mapperClass);
}
$cols = $mapper->map($props);
}
if ($authVars->mapping && !empty($authVars->mapping)) {
$cols = array();
foreach ($authVars->mapping as $mappedProp => $col) {
if ($col) {
$cols[$col] = !empty($props[$mappedProp]) ? $props[$mappedProp] : null;
}
}
} else {
throw new Garp_Auth_Exception('This authentication method requires '.
' a mapping of columns in application.ini.');
}
return array_merge($cols, $this->_extendedUserColumns);
} | [
"protected",
"function",
"_mapProperties",
"(",
"array",
"$",
"props",
")",
"{",
"$",
"authVars",
"=",
"$",
"this",
"->",
"_getAuthVars",
"(",
")",
";",
"if",
"(",
"$",
"authVars",
"->",
"mapperClass",
")",
"{",
"$",
"mapper",
"=",
"new",
"$",
"authVar... | Map properties coming from the 3rd party to columns used in our database
@param Array $props
@return Array | [
"Map",
"properties",
"coming",
"from",
"the",
"3rd",
"party",
"to",
"columns",
"used",
"in",
"our",
"database"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Abstract.php#L96-L119 | train |
grrr-amsterdam/garp3 | library/Garp/3rdParty/codebird/codebird.php | Codebird.oauth_authorize | public function oauth_authorize($force_login = NULL, $screen_name = NULL)
{
if ($this->_oauth_token == null) {
throw new \Exception('To get the authorize URL, the OAuth token must be set.');
}
$url = self::$_endpoint_oauth . 'oauth/authorize?oauth_token=' . $this->_url($this->_oauth_token);
if ($force_login) {
$url .= "&force_login=1";
}
if ($screen_name) {
$url .= "&screen_name=" . $screen_name;
}
return $url;
} | php | public function oauth_authorize($force_login = NULL, $screen_name = NULL)
{
if ($this->_oauth_token == null) {
throw new \Exception('To get the authorize URL, the OAuth token must be set.');
}
$url = self::$_endpoint_oauth . 'oauth/authorize?oauth_token=' . $this->_url($this->_oauth_token);
if ($force_login) {
$url .= "&force_login=1";
}
if ($screen_name) {
$url .= "&screen_name=" . $screen_name;
}
return $url;
} | [
"public",
"function",
"oauth_authorize",
"(",
"$",
"force_login",
"=",
"NULL",
",",
"$",
"screen_name",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_oauth_token",
"==",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'To get the author... | Gets the OAuth authorize URL for the current request token
@return string The OAuth authorize URL | [
"Gets",
"the",
"OAuth",
"authorize",
"URL",
"for",
"the",
"current",
"request",
"token"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/3rdParty/codebird/codebird.php#L520-L533 | train |
grrr-amsterdam/garp3 | library/Garp/3rdParty/codebird/codebird.php | Codebird.oauth2_token | public function oauth2_token()
{
if (! function_exists('curl_init')) {
throw new \Exception('To make API requests, the PHP curl extension must be available.');
}
if (self::$_oauth_consumer_key == null) {
throw new \Exception('To obtain a bearer token, the consumer key must be set.');
}
$ch = false;
$post_fields = array(
'grant_type' => 'client_credentials'
);
$url = self::$_endpoint_oauth . 'oauth2/token';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');
curl_setopt($ch, CURLOPT_USERPWD, self::$_oauth_consumer_key . ':' . self::$_oauth_consumer_secret);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Expect:'
));
$reply = curl_exec($ch);
// certificate validation results
$validation_result = curl_errno($ch);
if (in_array(
$validation_result,
array(
CURLE_SSL_CERTPROBLEM,
CURLE_SSL_CACERT,
CURLE_SSL_CACERT_BADFILE,
CURLE_SSL_CRL_BADFILE,
CURLE_SSL_ISSUER_ERROR
)
)
) {
throw new \Exception('Error ' . $validation_result . ' while validating the Twitter API certificate.');
}
$httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$reply = $this->_parseApiReply('oauth2/token', $reply);
switch ($this->_return_format) {
case CODEBIRD_RETURNFORMAT_ARRAY:
$reply['httpstatus'] = $httpstatus;
if ($httpstatus == 200) {
self::setBearerToken($reply['access_token']);
}
break;
case CODEBIRD_RETURNFORMAT_JSON:
if ($httpstatus == 200) {
$parsed = json_decode($reply);
self::setBearerToken($parsed->access_token);
}
break;
case CODEBIRD_RETURNFORMAT_OBJECT:
$reply->httpstatus = $httpstatus;
if ($httpstatus == 200) {
self::setBearerToken($reply->access_token);
}
break;
}
return $reply;
} | php | public function oauth2_token()
{
if (! function_exists('curl_init')) {
throw new \Exception('To make API requests, the PHP curl extension must be available.');
}
if (self::$_oauth_consumer_key == null) {
throw new \Exception('To obtain a bearer token, the consumer key must be set.');
}
$ch = false;
$post_fields = array(
'grant_type' => 'client_credentials'
);
$url = self::$_endpoint_oauth . 'oauth2/token';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');
curl_setopt($ch, CURLOPT_USERPWD, self::$_oauth_consumer_key . ':' . self::$_oauth_consumer_secret);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Expect:'
));
$reply = curl_exec($ch);
// certificate validation results
$validation_result = curl_errno($ch);
if (in_array(
$validation_result,
array(
CURLE_SSL_CERTPROBLEM,
CURLE_SSL_CACERT,
CURLE_SSL_CACERT_BADFILE,
CURLE_SSL_CRL_BADFILE,
CURLE_SSL_ISSUER_ERROR
)
)
) {
throw new \Exception('Error ' . $validation_result . ' while validating the Twitter API certificate.');
}
$httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$reply = $this->_parseApiReply('oauth2/token', $reply);
switch ($this->_return_format) {
case CODEBIRD_RETURNFORMAT_ARRAY:
$reply['httpstatus'] = $httpstatus;
if ($httpstatus == 200) {
self::setBearerToken($reply['access_token']);
}
break;
case CODEBIRD_RETURNFORMAT_JSON:
if ($httpstatus == 200) {
$parsed = json_decode($reply);
self::setBearerToken($parsed->access_token);
}
break;
case CODEBIRD_RETURNFORMAT_OBJECT:
$reply->httpstatus = $httpstatus;
if ($httpstatus == 200) {
self::setBearerToken($reply->access_token);
}
break;
}
return $reply;
} | [
"public",
"function",
"oauth2_token",
"(",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'curl_init'",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'To make API requests, the PHP curl extension must be available.'",
")",
";",
"}",
"if",
"(",
"self"... | Gets the OAuth bearer token
@return string The OAuth bearer token | [
"Gets",
"the",
"OAuth",
"bearer",
"token"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/3rdParty/codebird/codebird.php#L541-L609 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Sentry.php | Garp_Service_Sentry._readGarpVersion | protected function _readGarpVersion() {
$versionInCaseOfError = 'v0.0.0';
$lockFilePath = APPLICATION_PATH . '/../composer.lock';
if (!file_exists($lockFilePath)) {
return $versionInCaseOfError;
}
$lockFile = json_decode(file_get_contents($lockFilePath), true);
$packages = $lockFile['packages'];
return array_reduce(
$packages,
function ($prevVersion, $package) {
// Found Garp? Return its version
if ($package['name'] === 'grrr-amsterdam/garp3') {
return $package['version'];
}
// Otherwise return whatever version we previously got
return $prevVersion;
},
// Initial value
$versionInCaseOfError
);
} | php | protected function _readGarpVersion() {
$versionInCaseOfError = 'v0.0.0';
$lockFilePath = APPLICATION_PATH . '/../composer.lock';
if (!file_exists($lockFilePath)) {
return $versionInCaseOfError;
}
$lockFile = json_decode(file_get_contents($lockFilePath), true);
$packages = $lockFile['packages'];
return array_reduce(
$packages,
function ($prevVersion, $package) {
// Found Garp? Return its version
if ($package['name'] === 'grrr-amsterdam/garp3') {
return $package['version'];
}
// Otherwise return whatever version we previously got
return $prevVersion;
},
// Initial value
$versionInCaseOfError
);
} | [
"protected",
"function",
"_readGarpVersion",
"(",
")",
"{",
"$",
"versionInCaseOfError",
"=",
"'v0.0.0'",
";",
"$",
"lockFilePath",
"=",
"APPLICATION_PATH",
".",
"'/../composer.lock'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"lockFilePath",
")",
")",
"{",
... | Read Garp version from composer.lock. This will be available when Garp is installed as
dependency of some app.
@return string | [
"Read",
"Garp",
"version",
"from",
"composer",
".",
"lock",
".",
"This",
"will",
"be",
"available",
"when",
"Garp",
"is",
"installed",
"as",
"dependency",
"of",
"some",
"app",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Sentry.php#L73-L95 | train |
grrr-amsterdam/garp3 | library/Garp/Db/Table/Rowset/Iterator.php | Garp_Db_Table_Rowset_Iterator.walk | public function walk() {
$this->_beforeWalk();
foreach ($this->_result as $result) {
call_user_func($this->_function, $result);
}
$this->_afterWalk();
} | php | public function walk() {
$this->_beforeWalk();
foreach ($this->_result as $result) {
call_user_func($this->_function, $result);
}
$this->_afterWalk();
} | [
"public",
"function",
"walk",
"(",
")",
"{",
"$",
"this",
"->",
"_beforeWalk",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_result",
"as",
"$",
"result",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"_function",
",",
"$",
"result",
")",... | Process the result, execute the given function for every row.
Make sure to rewind rowsets at the end.
@return Void | [
"Process",
"the",
"result",
"execute",
"the",
"given",
"function",
"for",
"every",
"row",
".",
"Make",
"sure",
"to",
"rewind",
"rowsets",
"at",
"the",
"end",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Db/Table/Rowset/Iterator.php#L45-L51 | train |
grrr-amsterdam/garp3 | library/Garp/Db/Table/Rowset/Iterator.php | Garp_Db_Table_Rowset_Iterator._afterWalk | protected function _afterWalk() {
// return the pointer of a Rowset to 0
if ($this->_result instanceof Garp_Db_Table_Rowset) {
$this->_result->rewind();
} else {
// also, return results to the original format if it was no Rowset to begin with.
$this->_result = $this->_result[0];
}
} | php | protected function _afterWalk() {
// return the pointer of a Rowset to 0
if ($this->_result instanceof Garp_Db_Table_Rowset) {
$this->_result->rewind();
} else {
// also, return results to the original format if it was no Rowset to begin with.
$this->_result = $this->_result[0];
}
} | [
"protected",
"function",
"_afterWalk",
"(",
")",
"{",
"// return the pointer of a Rowset to 0",
"if",
"(",
"$",
"this",
"->",
"_result",
"instanceof",
"Garp_Db_Table_Rowset",
")",
"{",
"$",
"this",
"->",
"_result",
"->",
"rewind",
"(",
")",
";",
"}",
"else",
"... | Callback after walking over the results.
Returns everything to its original state.
@return Void | [
"Callback",
"after",
"walking",
"over",
"the",
"results",
".",
"Returns",
"everything",
"to",
"its",
"original",
"state",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Db/Table/Rowset/Iterator.php#L71-L79 | train |
grrr-amsterdam/garp3 | library/Garp/Db/Table/Rowset/Iterator.php | Garp_Db_Table_Rowset_Iterator.setResult | public function setResult(&$result) {
if (!is_null($result) &&
!$result instanceof Garp_Db_Table_Row &&
!$result instanceof Garp_Db_Table_Rowset) {
throw new InvalidArgumentException(__METHOD__.' expects parameter 1 to be a'.
'Garp_Db_Table_Row or Garp_Db_Table_Rowset. '.gettype($result).' given.');
}
$this->_result = $result;
} | php | public function setResult(&$result) {
if (!is_null($result) &&
!$result instanceof Garp_Db_Table_Row &&
!$result instanceof Garp_Db_Table_Rowset) {
throw new InvalidArgumentException(__METHOD__.' expects parameter 1 to be a'.
'Garp_Db_Table_Row or Garp_Db_Table_Rowset. '.gettype($result).' given.');
}
$this->_result = $result;
} | [
"public",
"function",
"setResult",
"(",
"&",
"$",
"result",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"result",
")",
"&&",
"!",
"$",
"result",
"instanceof",
"Garp_Db_Table_Row",
"&&",
"!",
"$",
"result",
"instanceof",
"Garp_Db_Table_Rowset",
")",
"{",... | Set the result
@param Garp_Db_Table_Row|Garp_Db_Table_Rowset $result The query result
@return Void | [
"Set",
"the",
"result"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Db/Table/Rowset/Iterator.php#L96-L104 | train |
grrr-amsterdam/garp3 | library/Garp/Db/Table/Row.php | Garp_Db_Table_Row.findParentRow | public function findParentRow($parentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
{
$db = $this->_getTable()->getAdapter();
if (is_string($parentTable)) {
$parentTable = $this->_getTableFromString($parentTable);
}
if (!$parentTable instanceof Zend_Db_Table_Abstract) {
$type = gettype($parentTable);
if ($type == 'object') {
$type = get_class($parentTable);
}
throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
}
// even if we are interacting between a table defined in a class and a
// table via extension, ensure to persist the definition
if (($tableDefinition = $this->_table->getDefinition()) !== null
&& ($parentTable->getDefinition() == null)
) {
$parentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
}
if ($select === null) {
$select = $parentTable->select();
} else {
$select->setTable($parentTable);
}
$map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);
// iterate the map, creating the proper wheres
for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
$dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
$value = $this->_data[$dependentColumnName];
// Use adapter from parent table to ensure correct query construction
$parentDb = $parentTable->getAdapter();
$parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
$parentColumn = $parentDb->quoteIdentifier($parentTable->getName()) . '.';
$parentColumn .= $parentDb->quoteIdentifier($parentColumnName, true);
$parentInfo = $parentTable->info();
// determine where part
$type = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
$nullable = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['NULLABLE'];
if ($value === null && $nullable == true) {
$select->where("$parentColumn IS NULL");
} elseif ($value === null && $nullable == false) {
return null;
} else {
$select->where("$parentColumn = ?", $value, $type);
}
}
return $parentTable->fetchRow($select);
} | php | public function findParentRow($parentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
{
$db = $this->_getTable()->getAdapter();
if (is_string($parentTable)) {
$parentTable = $this->_getTableFromString($parentTable);
}
if (!$parentTable instanceof Zend_Db_Table_Abstract) {
$type = gettype($parentTable);
if ($type == 'object') {
$type = get_class($parentTable);
}
throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
}
// even if we are interacting between a table defined in a class and a
// table via extension, ensure to persist the definition
if (($tableDefinition = $this->_table->getDefinition()) !== null
&& ($parentTable->getDefinition() == null)
) {
$parentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
}
if ($select === null) {
$select = $parentTable->select();
} else {
$select->setTable($parentTable);
}
$map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);
// iterate the map, creating the proper wheres
for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
$dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
$value = $this->_data[$dependentColumnName];
// Use adapter from parent table to ensure correct query construction
$parentDb = $parentTable->getAdapter();
$parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
$parentColumn = $parentDb->quoteIdentifier($parentTable->getName()) . '.';
$parentColumn .= $parentDb->quoteIdentifier($parentColumnName, true);
$parentInfo = $parentTable->info();
// determine where part
$type = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
$nullable = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['NULLABLE'];
if ($value === null && $nullable == true) {
$select->where("$parentColumn IS NULL");
} elseif ($value === null && $nullable == false) {
return null;
} else {
$select->where("$parentColumn = ?", $value, $type);
}
}
return $parentTable->fetchRow($select);
} | [
"public",
"function",
"findParentRow",
"(",
"$",
"parentTable",
",",
"$",
"ruleKey",
"=",
"null",
",",
"Zend_Db_Table_Select",
"$",
"select",
"=",
"null",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"_getTable",
"(",
")",
"->",
"getAdapter",
"(",
")",
... | ATTENTION
This method is copied from Zend_Db_Table_Row_Abstract.
It is altered to add the table name to the WHERE clause. So instead of
WHERE id = 42
the query becomes:
WHERE MyStuff.id = 42
Query a parent table to retrieve the single row matching the current row.
@param string|Zend_Db_Table_Abstract $parentTable
@param string OPTIONAL $ruleKey
@param Zend_Db_Table_Select OPTIONAL $select
@return Zend_Db_Table_Row_Abstract Query result from $parentTable
@throws Zend_Db_Table_Row_Exception If $parentTable is not a table or is not loadable. | [
"ATTENTION",
"This",
"method",
"is",
"copied",
"from",
"Zend_Db_Table_Row_Abstract",
".",
"It",
"is",
"altered",
"to",
"add",
"the",
"table",
"name",
"to",
"the",
"WHERE",
"clause",
".",
"So",
"instead",
"of"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Db/Table/Row.php#L243-L300 | train |
grrr-amsterdam/garp3 | library/Garp/Db/Table/Row.php | Garp_Db_Table_Row.setRelated | public function setRelated($binding, $rowset) {
$this->_related[$binding] = !is_null($rowset) ? $rowset : array();
return $this;
} | php | public function setRelated($binding, $rowset) {
$this->_related[$binding] = !is_null($rowset) ? $rowset : array();
return $this;
} | [
"public",
"function",
"setRelated",
"(",
"$",
"binding",
",",
"$",
"rowset",
")",
"{",
"$",
"this",
"->",
"_related",
"[",
"$",
"binding",
"]",
"=",
"!",
"is_null",
"(",
"$",
"rowset",
")",
"?",
"$",
"rowset",
":",
"array",
"(",
")",
";",
"return",... | Set a related rowset as property of this row.
@param string $binding An alias for storing the binding name
@param Garp_Db_Table_Row|Garp_Db_Table_Rowset $rowset The related rowset
@return Garp_Db_Table_Row $this | [
"Set",
"a",
"related",
"rowset",
"as",
"property",
"of",
"this",
"row",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Db/Table/Row.php#L329-L332 | train |
grrr-amsterdam/garp3 | library/Garp/Db/Table/Row.php | Garp_Db_Table_Row.getRelated | public function getRelated($binding = null) {
if (is_null($binding)) {
return $this->_related;
}
return $this->_related[$binding];
} | php | public function getRelated($binding = null) {
if (is_null($binding)) {
return $this->_related;
}
return $this->_related[$binding];
} | [
"public",
"function",
"getRelated",
"(",
"$",
"binding",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"binding",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_related",
";",
"}",
"return",
"$",
"this",
"->",
"_related",
"[",
"$",
"binding",... | Get a related rowset.
@param string $binding The alias for the related rowset
@return Garp_Db_Table_Row|Garp_Db_Table_Rowset | [
"Get",
"a",
"related",
"rowset",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Db/Table/Row.php#L340-L345 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Videoable.php | Garp_Model_Behavior_Videoable._setup | protected function _setup($config) {
if (empty($config['vimeo'])) {
$config['vimeo'] = array();
}
if (empty($config['youtube'])) {
$config['youtube'] = array();
}
$this->_config = $config;
} | php | protected function _setup($config) {
if (empty($config['vimeo'])) {
$config['vimeo'] = array();
}
if (empty($config['youtube'])) {
$config['youtube'] = array();
}
$this->_config = $config;
} | [
"protected",
"function",
"_setup",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"config",
"[",
"'vimeo'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'vimeo'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"co... | Setup the behavior - this configures the keys used to map service data to local database data.
Make sure to add a "vimeo" and a "youtube" key for the respective services.
@see Garp_Model_Behavior_Youtubeable and @see Garp_Model_Behavior_Vimeoable for the default mapping.
@param Array $config
@return Void | [
"Setup",
"the",
"behavior",
"-",
"this",
"configures",
"the",
"keys",
"used",
"to",
"map",
"service",
"data",
"to",
"local",
"database",
"data",
".",
"Make",
"sure",
"to",
"add",
"a",
"vimeo",
"and",
"a",
"youtube",
"key",
"for",
"the",
"respective",
"se... | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Videoable.php#L30-L38 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Videoable.php | Garp_Model_Behavior_Videoable._beforeSave | protected function _beforeSave(&$args, $event) {
$data = &$args[1];
if (!empty($data['url'])) {
$url = $data['url'];
if ($this->_isYouTubeUrl($url)) {
// check for YouTube
$behavior = new Garp_Model_Behavior_YouTubeable($this->_config['youtube']);
$data['type'] = 'youtube';
} elseif ($this->_isVimeoUrl($url)) {
// check for Vimeo
$behavior = new Garp_Model_Behavior_Vimeoable($this->_config['vimeo']);
$data['type'] = 'vimeo';
} else {
$error = sprintf(self::ERROR_INVALID_VIDEO_URL, $url);
throw new Garp_Model_Behavior_Videoable_Exception_InvalidUrl($error);
}
$behavior->{$event}($args);
}
} | php | protected function _beforeSave(&$args, $event) {
$data = &$args[1];
if (!empty($data['url'])) {
$url = $data['url'];
if ($this->_isYouTubeUrl($url)) {
// check for YouTube
$behavior = new Garp_Model_Behavior_YouTubeable($this->_config['youtube']);
$data['type'] = 'youtube';
} elseif ($this->_isVimeoUrl($url)) {
// check for Vimeo
$behavior = new Garp_Model_Behavior_Vimeoable($this->_config['vimeo']);
$data['type'] = 'vimeo';
} else {
$error = sprintf(self::ERROR_INVALID_VIDEO_URL, $url);
throw new Garp_Model_Behavior_Videoable_Exception_InvalidUrl($error);
}
$behavior->{$event}($args);
}
} | [
"protected",
"function",
"_beforeSave",
"(",
"&",
"$",
"args",
",",
"$",
"event",
")",
"{",
"$",
"data",
"=",
"&",
"$",
"args",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"url",
"=",
... | Custom callback for both insert and update
@param Array $args
@param String $event
@return Void | [
"Custom",
"callback",
"for",
"both",
"insert",
"and",
"update"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Videoable.php#L67-L85 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/Cache.php | Garp_Cli_Command_Cache.clear | public function clear(array $args = array()) {
$app = Zend_Registry::get('application');
$bootstrap = $app->getBootstrap();
$cacheDir = false;
if ($bootstrap && $bootstrap->getResource('cachemanager')) {
$cacheManager = $bootstrap->getResource('cachemanager');
$cache = $cacheManager->getCache(Zend_Cache_Manager::PAGECACHE);
$cacheDir = $cache->getBackend()->getOption('public_dir');
}
Garp_Cli::lineOut('Initialise cache clear');
$messageBag = Garp_Cache_Manager::purge($args, true, $cacheDir);
Garp_Cli::lineOut(implode("\n", $messageBag));
return true;
} | php | public function clear(array $args = array()) {
$app = Zend_Registry::get('application');
$bootstrap = $app->getBootstrap();
$cacheDir = false;
if ($bootstrap && $bootstrap->getResource('cachemanager')) {
$cacheManager = $bootstrap->getResource('cachemanager');
$cache = $cacheManager->getCache(Zend_Cache_Manager::PAGECACHE);
$cacheDir = $cache->getBackend()->getOption('public_dir');
}
Garp_Cli::lineOut('Initialise cache clear');
$messageBag = Garp_Cache_Manager::purge($args, true, $cacheDir);
Garp_Cli::lineOut(implode("\n", $messageBag));
return true;
} | [
"public",
"function",
"clear",
"(",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"app",
"=",
"Zend_Registry",
"::",
"get",
"(",
"'application'",
")",
";",
"$",
"bootstrap",
"=",
"$",
"app",
"->",
"getBootstrap",
"(",
")",
";",
"$",
... | Clear all the cache
@param array $args Tags.
@return bool | [
"Clear",
"all",
"the",
"cache"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Cache.php#L21-L35 | train |
grrr-amsterdam/garp3 | application/modules/g/views/helpers/FormText.php | G_View_Helper_FormText.formText | public function formText($name, $value = null, $attribs = null) {
$info = $this->_getInfo($name, $value, $attribs);
extract($info); // name, value, attribs, options, listsep, disable
// build the element
$disabled = '';
if ($disable) {
// disabled
$disabled = ' disabled="disabled"';
}
// XHTML or HTML end tag?
$endTag = ' />';
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
$endTag = '>';
}
$type = 'text';
if ($this->view->doctype()->isHtml5()
&& isset($attribs['type'])
&& in_array($attribs['type'], $this->_allowedTypes)
) {
$type = $attribs['type'];
}
unset($attribs['type']);
$xhtml = '<input type="' . $type . '"'
. ' name="' . $this->view->escape($name) . '"'
. ' id="' . $this->view->escape($id) . '"'
. ' value="' . $this->view->escape($value) . '"'
. $disabled
. $this->_htmlAttribs($attribs)
. $endTag;
return $xhtml;
} | php | public function formText($name, $value = null, $attribs = null) {
$info = $this->_getInfo($name, $value, $attribs);
extract($info); // name, value, attribs, options, listsep, disable
// build the element
$disabled = '';
if ($disable) {
// disabled
$disabled = ' disabled="disabled"';
}
// XHTML or HTML end tag?
$endTag = ' />';
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
$endTag = '>';
}
$type = 'text';
if ($this->view->doctype()->isHtml5()
&& isset($attribs['type'])
&& in_array($attribs['type'], $this->_allowedTypes)
) {
$type = $attribs['type'];
}
unset($attribs['type']);
$xhtml = '<input type="' . $type . '"'
. ' name="' . $this->view->escape($name) . '"'
. ' id="' . $this->view->escape($id) . '"'
. ' value="' . $this->view->escape($value) . '"'
. $disabled
. $this->_htmlAttribs($attribs)
. $endTag;
return $xhtml;
} | [
"public",
"function",
"formText",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"attribs",
"=",
"null",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"_getInfo",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"attribs",
")",
";",
... | Generates a 'text' element.
@param string|array $name If a string, the element name.
If an array, all other parameters are ignored,
and the array elements are used in place of added parameters.
@param mixed $value The element value.
@param array $attribs Attributes for the element tag.
@return string | [
"Generates",
"a",
"text",
"element",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/FormText.php#L32-L65 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/Js/Model/Abstract.php | Garp_Spawn_Js_Model_Abstract._getViewObject | protected function _getViewObject() {
if (!Zend_Registry::isRegistered('application')) {
throw new Exception('Application is not registered.');
}
$bootstrap = Zend_Registry::get('application')->getBootstrap();
$view = $bootstrap->getResource('View');
// Unfortunately specific conditional required when using the Ano_ZFTwig package.
// This switches the rendering engine from twig to php, since the Spawn templates are still
// in php.
if ($view instanceof Ano_View) {
$view->setTemplateEngine('php');
}
return $view;
} | php | protected function _getViewObject() {
if (!Zend_Registry::isRegistered('application')) {
throw new Exception('Application is not registered.');
}
$bootstrap = Zend_Registry::get('application')->getBootstrap();
$view = $bootstrap->getResource('View');
// Unfortunately specific conditional required when using the Ano_ZFTwig package.
// This switches the rendering engine from twig to php, since the Spawn templates are still
// in php.
if ($view instanceof Ano_View) {
$view->setTemplateEngine('php');
}
return $view;
} | [
"protected",
"function",
"_getViewObject",
"(",
")",
"{",
"if",
"(",
"!",
"Zend_Registry",
"::",
"isRegistered",
"(",
"'application'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Application is not registered.'",
")",
";",
"}",
"$",
"bootstrap",
"=",
"Z... | Returns a configured view object
@return Zend_View_Interface | [
"Returns",
"a",
"configured",
"view",
"object"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Js/Model/Abstract.php#L54-L69 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Crontab.php | Garp_Cli_Crontab.fetchAll | public function fetchAll() {
$crontab = $this->_exec('crontab -l');
$crontab = trim($crontab);
if (preg_match('/no crontab for/', $crontab)) {
return null;
} else {
$cronjobs = explode("\n", $crontab);
return $cronjobs;
}
} | php | public function fetchAll() {
$crontab = $this->_exec('crontab -l');
$crontab = trim($crontab);
if (preg_match('/no crontab for/', $crontab)) {
return null;
} else {
$cronjobs = explode("\n", $crontab);
return $cronjobs;
}
} | [
"public",
"function",
"fetchAll",
"(",
")",
"{",
"$",
"crontab",
"=",
"$",
"this",
"->",
"_exec",
"(",
"'crontab -l'",
")",
";",
"$",
"crontab",
"=",
"trim",
"(",
"$",
"crontab",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/no crontab for/'",
",",
"$",
... | Fetch current jobs
@return array | [
"Fetch",
"current",
"jobs"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Crontab.php#L23-L32 | train |
grrr-amsterdam/garp3 | library/Garp/Content/Upload/Storage/Type/Abstract.php | Garp_Content_Upload_Storage_Type_Abstract._getRelPath | protected function _getRelPath($filename, $type) {
$ini = $this->_getIni();
return $ini->cdn->path->upload->{$type} . DIRECTORY_SEPARATOR . $filename;
} | php | protected function _getRelPath($filename, $type) {
$ini = $this->_getIni();
return $ini->cdn->path->upload->{$type} . DIRECTORY_SEPARATOR . $filename;
} | [
"protected",
"function",
"_getRelPath",
"(",
"$",
"filename",
",",
"$",
"type",
")",
"{",
"$",
"ini",
"=",
"$",
"this",
"->",
"_getIni",
"(",
")",
";",
"return",
"$",
"ini",
"->",
"cdn",
"->",
"path",
"->",
"upload",
"->",
"{",
"$",
"type",
"}",
... | Returns the relative path to this filetype
@param String $type Filetype, should be one of $this->_uploadTypes
@return String Relative path to this type of file | [
"Returns",
"the",
"relative",
"path",
"to",
"this",
"filetype"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Upload/Storage/Type/Abstract.php#L66-L69 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Gofilex.php | Garp_Service_Gofilex.getMovies | public function getMovies() {
try {
$response = $this->_client->GETREPORT('film');
$this->_logTraffic();
} catch (Exception $e) {
$this->_throwException($e, 'GETREPORT(film)');
}
return $response->GENERALINFOARRAY;
} | php | public function getMovies() {
try {
$response = $this->_client->GETREPORT('film');
$this->_logTraffic();
} catch (Exception $e) {
$this->_throwException($e, 'GETREPORT(film)');
}
return $response->GENERALINFOARRAY;
} | [
"public",
"function",
"getMovies",
"(",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_client",
"->",
"GETREPORT",
"(",
"'film'",
")",
";",
"$",
"this",
"->",
"_logTraffic",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
... | Get all movies
@return Array | [
"Get",
"all",
"movies"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Gofilex.php#L44-L52 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Gofilex.php | Garp_Service_Gofilex.getMovieUnavailability | public function getMovieUnavailability(array $args) {
$args = $args instanceof Garp_Util_Configuration ? $args : new Garp_Util_Configuration($args);
$args->obligate('movieId')
->obligate('distributorId')
->setDefault('fromDate', date('Ymd'))
->setDefault('orderId', uniqid())
;
try {
$response = $this->_client->GETPRINTSTATUS(
$args['orderId'],
$args['movieId'],
$args['distributorId'],
$args['fromDate']
);
$this->_logTraffic();
} catch (Exception $e) {
$this->_throwException($e, 'GETPRINTSTATUS', $args);
}
$out = array();
foreach ($response->PRINTSTATUSARRAY as $medium) {
if (!is_object($medium)) {
continue;
}
if (!array_key_exists($medium->TYPEDRAGER, $out)) {
$out[$medium->TYPEDRAGER] = array();
}
// Fools leave whitespace instead of NULL
$medium->GEBLOKKEERDEPERIODE = trim($medium->GEBLOKKEERDEPERIODE);
if ($medium->GEBLOKKEERDEPERIODE) {
$dates = explode('-', $medium->GEBLOKKEERDEPERIODE);
$out[$medium->TYPEDRAGER][] = array(
strtotime($dates[0]),
strtotime($dates[1])
);
}
}
return $out;
} | php | public function getMovieUnavailability(array $args) {
$args = $args instanceof Garp_Util_Configuration ? $args : new Garp_Util_Configuration($args);
$args->obligate('movieId')
->obligate('distributorId')
->setDefault('fromDate', date('Ymd'))
->setDefault('orderId', uniqid())
;
try {
$response = $this->_client->GETPRINTSTATUS(
$args['orderId'],
$args['movieId'],
$args['distributorId'],
$args['fromDate']
);
$this->_logTraffic();
} catch (Exception $e) {
$this->_throwException($e, 'GETPRINTSTATUS', $args);
}
$out = array();
foreach ($response->PRINTSTATUSARRAY as $medium) {
if (!is_object($medium)) {
continue;
}
if (!array_key_exists($medium->TYPEDRAGER, $out)) {
$out[$medium->TYPEDRAGER] = array();
}
// Fools leave whitespace instead of NULL
$medium->GEBLOKKEERDEPERIODE = trim($medium->GEBLOKKEERDEPERIODE);
if ($medium->GEBLOKKEERDEPERIODE) {
$dates = explode('-', $medium->GEBLOKKEERDEPERIODE);
$out[$medium->TYPEDRAGER][] = array(
strtotime($dates[0]),
strtotime($dates[1])
);
}
}
return $out;
} | [
"public",
"function",
"getMovieUnavailability",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"args",
"=",
"$",
"args",
"instanceof",
"Garp_Util_Configuration",
"?",
"$",
"args",
":",
"new",
"Garp_Util_Configuration",
"(",
"$",
"args",
")",
";",
"$",
"args",
"->... | Fetch unavailability of a given movie
@param Array $args
@return Array | [
"Fetch",
"unavailability",
"of",
"a",
"given",
"movie"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Gofilex.php#L75-L113 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Gofilex.php | Garp_Service_Gofilex._throwException | protected function _throwException(Exception $e, $method, $args = array()) {
$this->_logTraffic();
// Mail Amstelfilm about this error
$ini = Zend_Registry::get('config');
if (!empty($ini->gofilex->errorReportEmailAddress)) {
$to = $ini->gofilex->errorReportEmailAddress;
$subject = 'Gofilex error report';
$message = "Hallo,\n\r\n\r".
"Er is een Gofilex fout opgetreden. Hier vindt u de details:\n\r\n\r".
"Fout: ".$e->getMessage()."\n\r".
"Gofilex API functie: $method\n\r".
"Parameters:\n";
foreach ($args as $key => $value) {
$message .= "$key: $value\n\r";
}
// Especially interesting is the submitted POST data, since here
// user-submitted movie data will reside
$message .= "\n\rPOST data (ingevuld in het formulier):\n\r";
if (empty($_POST)) {
$message .= "-\n\r";
} else {
foreach ($_POST as $key => $value) {
$message .= "$key: $value\n\r";
}
}
$mailer = new Garp_Mailer();
$mailer->send(array(
'to' => $to,
'subject' => $subject,
'message' => $message
));
}
throw $e;
} | php | protected function _throwException(Exception $e, $method, $args = array()) {
$this->_logTraffic();
// Mail Amstelfilm about this error
$ini = Zend_Registry::get('config');
if (!empty($ini->gofilex->errorReportEmailAddress)) {
$to = $ini->gofilex->errorReportEmailAddress;
$subject = 'Gofilex error report';
$message = "Hallo,\n\r\n\r".
"Er is een Gofilex fout opgetreden. Hier vindt u de details:\n\r\n\r".
"Fout: ".$e->getMessage()."\n\r".
"Gofilex API functie: $method\n\r".
"Parameters:\n";
foreach ($args as $key => $value) {
$message .= "$key: $value\n\r";
}
// Especially interesting is the submitted POST data, since here
// user-submitted movie data will reside
$message .= "\n\rPOST data (ingevuld in het formulier):\n\r";
if (empty($_POST)) {
$message .= "-\n\r";
} else {
foreach ($_POST as $key => $value) {
$message .= "$key: $value\n\r";
}
}
$mailer = new Garp_Mailer();
$mailer->send(array(
'to' => $to,
'subject' => $subject,
'message' => $message
));
}
throw $e;
} | [
"protected",
"function",
"_throwException",
"(",
"Exception",
"$",
"e",
",",
"$",
"method",
",",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_logTraffic",
"(",
")",
";",
"// Mail Amstelfilm about this error",
"$",
"ini",
"=",
"Zend_R... | Throw exception and do some logging.
@param Exception $e
@param String $method
@param Array $args
@return Void | [
"Throw",
"exception",
"and",
"do",
"some",
"logging",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Gofilex.php#L209-L246 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Gofilex.php | Garp_Service_Gofilex._logTraffic | protected function _logTraffic() {
if ('testing' !== APPLICATION_ENV) {
$lastRequest = $this->_client->getLastRequest();
$lastResponse = $this->_client->getLastResponse();
$filename = date('Y-m-d').'-gofilex.log';
$logMessage = "\n";
$logMessage .= '[REQUEST]'."\n";
$logMessage .= $lastRequest."\n\n";
$logMessage .= '[RESPONSE]'."\n";
$logMessage .= $lastResponse."\n\n";
dump($filename, $logMessage);
}
} | php | protected function _logTraffic() {
if ('testing' !== APPLICATION_ENV) {
$lastRequest = $this->_client->getLastRequest();
$lastResponse = $this->_client->getLastResponse();
$filename = date('Y-m-d').'-gofilex.log';
$logMessage = "\n";
$logMessage .= '[REQUEST]'."\n";
$logMessage .= $lastRequest."\n\n";
$logMessage .= '[RESPONSE]'."\n";
$logMessage .= $lastResponse."\n\n";
dump($filename, $logMessage);
}
} | [
"protected",
"function",
"_logTraffic",
"(",
")",
"{",
"if",
"(",
"'testing'",
"!==",
"APPLICATION_ENV",
")",
"{",
"$",
"lastRequest",
"=",
"$",
"this",
"->",
"_client",
"->",
"getLastRequest",
"(",
")",
";",
"$",
"lastResponse",
"=",
"$",
"this",
"->",
... | Keep track of all requests and their responses in a log file
@return Void | [
"Keep",
"track",
"of",
"all",
"requests",
"and",
"their",
"responses",
"in",
"a",
"log",
"file"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Gofilex.php#L253-L266 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Weighable.php | Garp_Model_Behavior_Weighable.beforeInsert | public function beforeInsert(&$args) {
$model = $args[0];
$data = &$args[1];
foreach ($this->_relationConfig as $foreignModel => $modelRelationConfig) {
$foreignKey = $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY];
// only act if the foreign key column is filled
if (!empty($data[$foreignKey])) {
$maxWeight = $this->findHighestWeight($model, $data[$foreignKey], $modelRelationConfig);
$data[$modelRelationConfig[self::WEIGHT_COLUMN_KEY]] = ($maxWeight+1);
}
}
} | php | public function beforeInsert(&$args) {
$model = $args[0];
$data = &$args[1];
foreach ($this->_relationConfig as $foreignModel => $modelRelationConfig) {
$foreignKey = $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY];
// only act if the foreign key column is filled
if (!empty($data[$foreignKey])) {
$maxWeight = $this->findHighestWeight($model, $data[$foreignKey], $modelRelationConfig);
$data[$modelRelationConfig[self::WEIGHT_COLUMN_KEY]] = ($maxWeight+1);
}
}
} | [
"public",
"function",
"beforeInsert",
"(",
"&",
"$",
"args",
")",
"{",
"$",
"model",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"data",
"=",
"&",
"$",
"args",
"[",
"1",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_relationConfig",
"as",
"$",
... | BeforeInsert callback, find and insert the current highest 'weight' value + 1
in the weight column
@param Array $args
@return Void | [
"BeforeInsert",
"callback",
"find",
"and",
"insert",
"the",
"current",
"highest",
"weight",
"value",
"+",
"1",
"in",
"the",
"weight",
"column"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Weighable.php#L81-L92 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Weighable.php | Garp_Model_Behavior_Weighable.beforeUpdate | public function beforeUpdate(&$args) {
$model = $args[0];
$data = &$args[1];
$where = $args[2];
foreach ($this->_relationConfig as $foreignModel => $modelRelationConfig) {
$foreignKey = $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY];
$weightColumn = $modelRelationConfig[self::WEIGHT_COLUMN_KEY];
/**
* Only act if the foreign key field is filled, since weight is calculated per foreign key.
* This means duplicate weight values might occur in the database, but the foreign key
* will always differ.
* You should be able to add a UNIQUE INDEX to your table containing the foreign key column and the
* weight column.
*/
if (array_key_exists($foreignKey, $data) && $data[$foreignKey]) {
/**
* If the weight column is not given in the new data, fetch it.
* This is quite the pickle, since the given WHERE clause might update (and thus fetch)
* multiple records, but we can only provide one set of modified data to apply to every
* matching record.
* This is currently not fixed. If a WHERE clause is given that matches multiple records,
* the current weight of the first record found is used.
*/
if (!array_key_exists($weightColumn, $data)) {
$data[$weightColumn] = $this->findCurrentWeight($model, $where, $data[$foreignKey], $modelRelationConfig);
}
// only act if the foreign key column is filled, and the weight column is null
if (!$data[$weightColumn]) {
$maxWeight = $this->findHighestWeight($model, $data[$foreignKey], $modelRelationConfig);
$data[$weightColumn] = ($maxWeight+1);
}
}
}
} | php | public function beforeUpdate(&$args) {
$model = $args[0];
$data = &$args[1];
$where = $args[2];
foreach ($this->_relationConfig as $foreignModel => $modelRelationConfig) {
$foreignKey = $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY];
$weightColumn = $modelRelationConfig[self::WEIGHT_COLUMN_KEY];
/**
* Only act if the foreign key field is filled, since weight is calculated per foreign key.
* This means duplicate weight values might occur in the database, but the foreign key
* will always differ.
* You should be able to add a UNIQUE INDEX to your table containing the foreign key column and the
* weight column.
*/
if (array_key_exists($foreignKey, $data) && $data[$foreignKey]) {
/**
* If the weight column is not given in the new data, fetch it.
* This is quite the pickle, since the given WHERE clause might update (and thus fetch)
* multiple records, but we can only provide one set of modified data to apply to every
* matching record.
* This is currently not fixed. If a WHERE clause is given that matches multiple records,
* the current weight of the first record found is used.
*/
if (!array_key_exists($weightColumn, $data)) {
$data[$weightColumn] = $this->findCurrentWeight($model, $where, $data[$foreignKey], $modelRelationConfig);
}
// only act if the foreign key column is filled, and the weight column is null
if (!$data[$weightColumn]) {
$maxWeight = $this->findHighestWeight($model, $data[$foreignKey], $modelRelationConfig);
$data[$weightColumn] = ($maxWeight+1);
}
}
}
} | [
"public",
"function",
"beforeUpdate",
"(",
"&",
"$",
"args",
")",
"{",
"$",
"model",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"data",
"=",
"&",
"$",
"args",
"[",
"1",
"]",
";",
"$",
"where",
"=",
"$",
"args",
"[",
"2",
"]",
";",
"foreach",
... | BeforeUpdate callback, find and insert current highest 'weight' value + 1, if it is null
@param Array $args
@return Void | [
"BeforeUpdate",
"callback",
"find",
"and",
"insert",
"current",
"highest",
"weight",
"value",
"+",
"1",
"if",
"it",
"is",
"null"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Weighable.php#L99-L134 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Weighable.php | Garp_Model_Behavior_Weighable.findHighestWeight | public function findHighestWeight(Garp_Model $model, $foreignKey, array $modelRelationConfig) {
$foreignKeyColumn = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY]);
$weightColumn = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::WEIGHT_COLUMN_KEY]);
$select = $model->select()
->from($model->getName(), array('max' => 'MAX('.$weightColumn.')'))
->where($foreignKeyColumn.' = ?', $foreignKey)
;
$result = $model->fetchRow($select);
if ($result && $result->max) {
return $result->max;
}
return 0;
} | php | public function findHighestWeight(Garp_Model $model, $foreignKey, array $modelRelationConfig) {
$foreignKeyColumn = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY]);
$weightColumn = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::WEIGHT_COLUMN_KEY]);
$select = $model->select()
->from($model->getName(), array('max' => 'MAX('.$weightColumn.')'))
->where($foreignKeyColumn.' = ?', $foreignKey)
;
$result = $model->fetchRow($select);
if ($result && $result->max) {
return $result->max;
}
return 0;
} | [
"public",
"function",
"findHighestWeight",
"(",
"Garp_Model",
"$",
"model",
",",
"$",
"foreignKey",
",",
"array",
"$",
"modelRelationConfig",
")",
"{",
"$",
"foreignKeyColumn",
"=",
"$",
"model",
"->",
"getAdapter",
"(",
")",
"->",
"quoteIdentifier",
"(",
"$",... | Find the highest weight value for a certain relationship with a foreign key
@param Garp_Model $model
@param Int $foreignKey
@param Array $modelRelationConfig
@return Int | [
"Find",
"the",
"highest",
"weight",
"value",
"for",
"a",
"certain",
"relationship",
"with",
"a",
"foreign",
"key"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Weighable.php#L143-L156 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Weighable.php | Garp_Model_Behavior_Weighable.addOrderClause | public function addOrderClause(Zend_Db_Select &$select) {
// Distill the WHERE class from the Select object
$where = $select->getPart(Zend_Db_Select::WHERE);
// Save the existing ORDER clause.
$originalOrder = $select->getPart(Zend_Db_Select::ORDER);
$select->reset(Zend_Db_Select::ORDER);
$alias = '';
if ($this->_modelAlias) {
$alias = $this->_modelAlias . '.';
}
/**
* If a registered foreign key (see self::_relationConfig) is found, this query is
* considered to be a related fetch() command, and an ORDER BY clause is added with
* the registered weight column.
*/
foreach ($where as $w) {
foreach ($this->_relationConfig as $model => $modelRelationConfig) {
if (strpos($w, $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY]) !== false) {
$select->order($alias . $modelRelationConfig[self::WEIGHT_COLUMN_KEY].' DESC');
}
}
}
// Return the existing ORDER clause, only this time '<weight-column> DESC' will be in front of it
foreach ($originalOrder as $order) {
// [0] = column, [1] = direction
if (is_array($order)) {
$order = $order[0].' '.$order[1];
}
$select->order($order);
}
} | php | public function addOrderClause(Zend_Db_Select &$select) {
// Distill the WHERE class from the Select object
$where = $select->getPart(Zend_Db_Select::WHERE);
// Save the existing ORDER clause.
$originalOrder = $select->getPart(Zend_Db_Select::ORDER);
$select->reset(Zend_Db_Select::ORDER);
$alias = '';
if ($this->_modelAlias) {
$alias = $this->_modelAlias . '.';
}
/**
* If a registered foreign key (see self::_relationConfig) is found, this query is
* considered to be a related fetch() command, and an ORDER BY clause is added with
* the registered weight column.
*/
foreach ($where as $w) {
foreach ($this->_relationConfig as $model => $modelRelationConfig) {
if (strpos($w, $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY]) !== false) {
$select->order($alias . $modelRelationConfig[self::WEIGHT_COLUMN_KEY].' DESC');
}
}
}
// Return the existing ORDER clause, only this time '<weight-column> DESC' will be in front of it
foreach ($originalOrder as $order) {
// [0] = column, [1] = direction
if (is_array($order)) {
$order = $order[0].' '.$order[1];
}
$select->order($order);
}
} | [
"public",
"function",
"addOrderClause",
"(",
"Zend_Db_Select",
"&",
"$",
"select",
")",
"{",
"// Distill the WHERE class from the Select object",
"$",
"where",
"=",
"$",
"select",
"->",
"getPart",
"(",
"Zend_Db_Select",
"::",
"WHERE",
")",
";",
"// Save the existing O... | Modify the order clause to reflect the record's weight
@param Zend_Db_Select $select | [
"Modify",
"the",
"order",
"clause",
"to",
"reflect",
"the",
"record",
"s",
"weight"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Weighable.php#L189-L222 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Weighable.php | Garp_Model_Behavior_Weighable.getWeightColumns | public function getWeightColumns() {
$out = array();
foreach ($this->_relationConfig as $i => $conf) {
$out[] = $conf[self::WEIGHT_COLUMN_KEY];
}
return $out;
} | php | public function getWeightColumns() {
$out = array();
foreach ($this->_relationConfig as $i => $conf) {
$out[] = $conf[self::WEIGHT_COLUMN_KEY];
}
return $out;
} | [
"public",
"function",
"getWeightColumns",
"(",
")",
"{",
"$",
"out",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_relationConfig",
"as",
"$",
"i",
"=>",
"$",
"conf",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"conf",
"[",
"sel... | Get used weight columns
@return Array | [
"Get",
"used",
"weight",
"columns"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Weighable.php#L246-L252 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command/I18n.php | Garp_Cli_Command_I18n.populateLocalizedRecords | public function populateLocalizedRecords(array $args = array()) {
Zend_Registry::get('CacheFrontend')->setOption('caching', false);
$mem = new Garp_Util_Memory();
$mem->useHighMemory();
$models = !empty($args) ? array($args[0]) : $this->_getInternationalizedModels();
array_walk($models, array($this, '_populateRecordsForModel'));
Zend_Registry::get('CacheFrontend')->setOption('caching', true);
Garp_Cache_Manager::purge();
Garp_Cli::lineOut('Done.');
return true;
} | php | public function populateLocalizedRecords(array $args = array()) {
Zend_Registry::get('CacheFrontend')->setOption('caching', false);
$mem = new Garp_Util_Memory();
$mem->useHighMemory();
$models = !empty($args) ? array($args[0]) : $this->_getInternationalizedModels();
array_walk($models, array($this, '_populateRecordsForModel'));
Zend_Registry::get('CacheFrontend')->setOption('caching', true);
Garp_Cache_Manager::purge();
Garp_Cli::lineOut('Done.');
return true;
} | [
"public",
"function",
"populateLocalizedRecords",
"(",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"Zend_Registry",
"::",
"get",
"(",
"'CacheFrontend'",
")",
"->",
"setOption",
"(",
"'caching'",
",",
"false",
")",
";",
"$",
"mem",
"=",
"new",
... | This updates your database to be compliant with the refactored Translatable behavior.
I18n views no longer use fallbacks to the default language records.
Therefore an update to existing databases is necessary. This command populates records in
non-default languages to provide the data that used to be fallen back on.
@param array $args
@return bool | [
"This",
"updates",
"your",
"database",
"to",
"be",
"compliant",
"with",
"the",
"refactored",
"Translatable",
"behavior",
".",
"I18n",
"views",
"no",
"longer",
"use",
"fallbacks",
"to",
"the",
"default",
"language",
"records",
".",
"Therefore",
"an",
"update",
... | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/I18n.php#L20-L33 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Db/Faker.php | Garp_Model_Db_Faker.createFakeRow | public function createFakeRow(array $fieldConfiguration, array $defaultValues = array()) {
// TODO For now, filter primary keys, assuming they will be auto-generated by the database.
$exclude = f\either(f\prop('primary'), f\prop_equals('origin', 'relation'));
$configWithoutPks = f\filter(f\not($exclude), $fieldConfiguration);
$self = $this;
return f\reduce(
function ($out, $field) use ($self) {
$fieldName = $field['name'];
if (array_key_exists($fieldName, $out)) {
return $out;
}
$out[$fieldName] = $self->getFakeValueForField($field);
return $out;
},
$defaultValues,
$configWithoutPks
);
} | php | public function createFakeRow(array $fieldConfiguration, array $defaultValues = array()) {
// TODO For now, filter primary keys, assuming they will be auto-generated by the database.
$exclude = f\either(f\prop('primary'), f\prop_equals('origin', 'relation'));
$configWithoutPks = f\filter(f\not($exclude), $fieldConfiguration);
$self = $this;
return f\reduce(
function ($out, $field) use ($self) {
$fieldName = $field['name'];
if (array_key_exists($fieldName, $out)) {
return $out;
}
$out[$fieldName] = $self->getFakeValueForField($field);
return $out;
},
$defaultValues,
$configWithoutPks
);
} | [
"public",
"function",
"createFakeRow",
"(",
"array",
"$",
"fieldConfiguration",
",",
"array",
"$",
"defaultValues",
"=",
"array",
"(",
")",
")",
"{",
"// TODO For now, filter primary keys, assuming they will be auto-generated by the database.",
"$",
"exclude",
"=",
"f",
"... | Create a row with fake values
@param array $fieldConfiguration As taken from Garp_Model_Db::getConfiguration()
@param array $defaultValues Any values you want to provide yourself
@return array | [
"Create",
"a",
"row",
"with",
"fake",
"values"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Faker.php#L31-L48 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Db/Faker.php | Garp_Model_Db_Faker.getFakeValueForField | public function getFakeValueForField(array $config) {
if (!f\prop('required', $config)) {
// Give optional fields a 10% chance (more or less) to be NULL
$diceRoll = $this->_faker->numberBetween(1, 100);
if ($diceRoll < 10) {
return f\prop('default', $config) ?: null;
}
}
if (f\prop('origin', $config) === 'relation') {
// TODO Do something intelligent here?
// I don't want to tightly couple this class to a database or model, but a random
// integer for a foreign key will most definitely result in an
// Integrity constraint violation when there's no seed data.
return null;
}
if ($config['type'] === 'text') {
return $this->_getFakeText($config);
}
if ($config['type'] === 'html') {
$value = $this->_faker->randomHtml(2, 3);
$htmlFilterable = new Garp_Model_Behavior_HtmlFilterable();
$config = $htmlFilterable->getDefaultConfig();
return $htmlFilterable->filter($value, $config);
}
if ($config['type'] === 'enum' || $config['type'] === 'set') {
$options = $config['options'];
$isAssoc = f\every('is_string', array_keys($options));
$randomPool = $isAssoc ? array_keys($options) : array_values($options);
return $this->_faker->randomElement($randomPool);
}
if ($config['type'] === 'email') {
return $this->_faker->email;
}
if ($config['type'] === 'url') {
return $this->_faker->url;
}
if ($config['type'] === 'checkbox') {
return $this->_faker->randomElement(array(0, 1));
}
if ($config['type'] === 'date' || $config['type'] === 'datetime') {
$value = $this->_faker->dateTimeBetween('-1 year', '+1 year');
$format = $config['type'] === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
return $value->format($format);
}
if ($config['type'] === 'time') {
return $this->_faker->time;
}
if ($config['type'] === 'imagefile') {
return 'image.jpg';
}
if ($config['type'] === 'document') {
return 'document.txt';
}
if ($config['type'] === 'numeric') {
return $this->_faker->randomDigit;
}
throw new InvalidArgumentException("Unknown type encountered: {$config['type']}");
} | php | public function getFakeValueForField(array $config) {
if (!f\prop('required', $config)) {
// Give optional fields a 10% chance (more or less) to be NULL
$diceRoll = $this->_faker->numberBetween(1, 100);
if ($diceRoll < 10) {
return f\prop('default', $config) ?: null;
}
}
if (f\prop('origin', $config) === 'relation') {
// TODO Do something intelligent here?
// I don't want to tightly couple this class to a database or model, but a random
// integer for a foreign key will most definitely result in an
// Integrity constraint violation when there's no seed data.
return null;
}
if ($config['type'] === 'text') {
return $this->_getFakeText($config);
}
if ($config['type'] === 'html') {
$value = $this->_faker->randomHtml(2, 3);
$htmlFilterable = new Garp_Model_Behavior_HtmlFilterable();
$config = $htmlFilterable->getDefaultConfig();
return $htmlFilterable->filter($value, $config);
}
if ($config['type'] === 'enum' || $config['type'] === 'set') {
$options = $config['options'];
$isAssoc = f\every('is_string', array_keys($options));
$randomPool = $isAssoc ? array_keys($options) : array_values($options);
return $this->_faker->randomElement($randomPool);
}
if ($config['type'] === 'email') {
return $this->_faker->email;
}
if ($config['type'] === 'url') {
return $this->_faker->url;
}
if ($config['type'] === 'checkbox') {
return $this->_faker->randomElement(array(0, 1));
}
if ($config['type'] === 'date' || $config['type'] === 'datetime') {
$value = $this->_faker->dateTimeBetween('-1 year', '+1 year');
$format = $config['type'] === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
return $value->format($format);
}
if ($config['type'] === 'time') {
return $this->_faker->time;
}
if ($config['type'] === 'imagefile') {
return 'image.jpg';
}
if ($config['type'] === 'document') {
return 'document.txt';
}
if ($config['type'] === 'numeric') {
return $this->_faker->randomDigit;
}
throw new InvalidArgumentException("Unknown type encountered: {$config['type']}");
} | [
"public",
"function",
"getFakeValueForField",
"(",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"f",
"\\",
"prop",
"(",
"'required'",
",",
"$",
"config",
")",
")",
"{",
"// Give optional fields a 10% chance (more or less) to be NULL",
"$",
"diceRoll",
"=",
... | Get single fake value for a field configuration.
@param array $config Configuration as taken from Garp_Model_Db::getFieldConfiguration()
@return mixed | [
"Get",
"single",
"fake",
"value",
"for",
"a",
"field",
"configuration",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Faker.php#L56-L126 | train |
grrr-amsterdam/garp3 | library/Garp/Shell/Command/Abstract.php | Garp_Shell_Command_Abstract.executeRemotely | public function executeRemotely(Garp_Shell_RemoteSession $session) {
$commandString = $this->renderThrottledCommandIfNecessary($session);
return $this->_executeStringRemotely($commandString, $session);
} | php | public function executeRemotely(Garp_Shell_RemoteSession $session) {
$commandString = $this->renderThrottledCommandIfNecessary($session);
return $this->_executeStringRemotely($commandString, $session);
} | [
"public",
"function",
"executeRemotely",
"(",
"Garp_Shell_RemoteSession",
"$",
"session",
")",
"{",
"$",
"commandString",
"=",
"$",
"this",
"->",
"renderThrottledCommandIfNecessary",
"(",
"$",
"session",
")",
";",
"return",
"$",
"this",
"->",
"_executeStringRemotely... | Executes the command through an SSH session in a remote terminal.
@return String The command's output | [
"Executes",
"the",
"command",
"through",
"an",
"SSH",
"session",
"in",
"a",
"remote",
"terminal",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Shell/Command/Abstract.php#L27-L30 | train |
grrr-amsterdam/garp3 | library/Garp/Shell/Command/Abstract.php | Garp_Shell_Command_Abstract._executeStringRemotely | protected function _executeStringRemotely($commandString, Garp_Shell_RemoteSession $session) {
if (!($stream = ssh2_exec($session->getSshSession(), $commandString))) {
return false;
}
stream_set_blocking($stream, true);
$content = stream_get_contents($stream);
$this->_bubbleSshErrors($stream, $commandString);
fclose($stream);
return $content;
} | php | protected function _executeStringRemotely($commandString, Garp_Shell_RemoteSession $session) {
if (!($stream = ssh2_exec($session->getSshSession(), $commandString))) {
return false;
}
stream_set_blocking($stream, true);
$content = stream_get_contents($stream);
$this->_bubbleSshErrors($stream, $commandString);
fclose($stream);
return $content;
} | [
"protected",
"function",
"_executeStringRemotely",
"(",
"$",
"commandString",
",",
"Garp_Shell_RemoteSession",
"$",
"session",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"stream",
"=",
"ssh2_exec",
"(",
"$",
"session",
"->",
"getSshSession",
"(",
")",
",",
"$",
"co... | Executes provided command string through an SSH session in a remote terminal.
@return String The command's output | [
"Executes",
"provided",
"command",
"string",
"through",
"an",
"SSH",
"session",
"in",
"a",
"remote",
"terminal",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Shell/Command/Abstract.php#L36-L47 | train |
grrr-amsterdam/garp3 | library/Garp/Shell/Command/Abstract.php | Garp_Shell_Command_Abstract.renderThrottledCommand | public function renderThrottledCommand(Garp_Shell_RemoteSession $session = null) {
$command = new Garp_Shell_Command_Decorator_Nice($this);
$ioNiceCommand = new Garp_Shell_Command_IoNiceIsAvailable();
$ioNiceCommandString = $ioNiceCommand->render();
$ioNiceIsAvailable = $session ?
$this->_executeStringRemotely($ioNiceCommandString, $session) :
$this->_executeStringLocally($ioNiceCommandString)
;
if ($ioNiceIsAvailable) {
$command = new Garp_Shell_Command_Decorator_IoNice($command);
}
return $command->render();
} | php | public function renderThrottledCommand(Garp_Shell_RemoteSession $session = null) {
$command = new Garp_Shell_Command_Decorator_Nice($this);
$ioNiceCommand = new Garp_Shell_Command_IoNiceIsAvailable();
$ioNiceCommandString = $ioNiceCommand->render();
$ioNiceIsAvailable = $session ?
$this->_executeStringRemotely($ioNiceCommandString, $session) :
$this->_executeStringLocally($ioNiceCommandString)
;
if ($ioNiceIsAvailable) {
$command = new Garp_Shell_Command_Decorator_IoNice($command);
}
return $command->render();
} | [
"public",
"function",
"renderThrottledCommand",
"(",
"Garp_Shell_RemoteSession",
"$",
"session",
"=",
"null",
")",
"{",
"$",
"command",
"=",
"new",
"Garp_Shell_Command_Decorator_Nice",
"(",
"$",
"this",
")",
";",
"$",
"ioNiceCommand",
"=",
"new",
"Garp_Shell_Command... | Returns the decorated version of this command, for throttling purposes.
@param Garp_Shell_RemoteSession $session Pass the session instance along if this is a remote server.
@return Garp_Shell_Command_Abstract | [
"Returns",
"the",
"decorated",
"version",
"of",
"this",
"command",
"for",
"throttling",
"purposes",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Shell/Command/Abstract.php#L78-L94 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/Model/Base.php | Garp_Spawn_Model_Base.materializeExtendedJsModels | public function materializeExtendedJsModels(Garp_Spawn_Model_Set $modelSet) {
$jsExtendedModel = new Garp_Spawn_Js_Model_Extended($this->id, $modelSet);
$jsExtendedModelOutput = $jsExtendedModel->render();
$jsAppExtendedFile = new Garp_Spawn_Js_Model_File_AppExtended($this);
$jsAppExtendedFile->save($jsExtendedModelOutput);
if ($this->module === 'garp') {
$jsGarpExtendedFile = new Garp_Spawn_Js_Model_File_GarpExtended($this);
$jsGarpExtendedFile->save($jsExtendedModelOutput);
}
} | php | public function materializeExtendedJsModels(Garp_Spawn_Model_Set $modelSet) {
$jsExtendedModel = new Garp_Spawn_Js_Model_Extended($this->id, $modelSet);
$jsExtendedModelOutput = $jsExtendedModel->render();
$jsAppExtendedFile = new Garp_Spawn_Js_Model_File_AppExtended($this);
$jsAppExtendedFile->save($jsExtendedModelOutput);
if ($this->module === 'garp') {
$jsGarpExtendedFile = new Garp_Spawn_Js_Model_File_GarpExtended($this);
$jsGarpExtendedFile->save($jsExtendedModelOutput);
}
} | [
"public",
"function",
"materializeExtendedJsModels",
"(",
"Garp_Spawn_Model_Set",
"$",
"modelSet",
")",
"{",
"$",
"jsExtendedModel",
"=",
"new",
"Garp_Spawn_Js_Model_Extended",
"(",
"$",
"this",
"->",
"id",
",",
"$",
"modelSet",
")",
";",
"$",
"jsExtendedModelOutput... | Creates extended model files, if necessary. | [
"Creates",
"extended",
"model",
"files",
"if",
"necessary",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Base.php#L49-L60 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/Model/Base.php | Garp_Spawn_Model_Base.renderJsBaseModel | public function renderJsBaseModel(Garp_Spawn_Model_Set $modelSet) {
$jsBaseModel = new Garp_Spawn_Js_Model_Base($this->id, $modelSet);
$jsBaseFile = new Garp_Spawn_Js_Model_File_Base($this);
return $jsBaseModel->render();
} | php | public function renderJsBaseModel(Garp_Spawn_Model_Set $modelSet) {
$jsBaseModel = new Garp_Spawn_Js_Model_Base($this->id, $modelSet);
$jsBaseFile = new Garp_Spawn_Js_Model_File_Base($this);
return $jsBaseModel->render();
} | [
"public",
"function",
"renderJsBaseModel",
"(",
"Garp_Spawn_Model_Set",
"$",
"modelSet",
")",
"{",
"$",
"jsBaseModel",
"=",
"new",
"Garp_Spawn_Js_Model_Base",
"(",
"$",
"this",
"->",
"id",
",",
"$",
"modelSet",
")",
";",
"$",
"jsBaseFile",
"=",
"new",
"Garp_Sp... | Creates JS base model file. | [
"Creates",
"JS",
"base",
"model",
"file",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Base.php#L65-L69 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Ui/ProgressBar.php | Garp_Cli_Ui_ProgressBar.display | public function display($message = null, $itemsLeftMessage = null) {
$this->_verifyTotalValue();
$this->_clearLine();
$this->_renderProgress();
if ($message) {
echo self::SPACING;
$itemsLeft = $this->_totalValue - $this->_currentValue;
$itemsLeft = number_format($itemsLeft, 0, ',', '.');
$output = $message . ', ' . sprintf($itemsLeftMessage, $itemsLeft);
echo substr($output, 0, $this->_getMaximumMessageLength());
}
} | php | public function display($message = null, $itemsLeftMessage = null) {
$this->_verifyTotalValue();
$this->_clearLine();
$this->_renderProgress();
if ($message) {
echo self::SPACING;
$itemsLeft = $this->_totalValue - $this->_currentValue;
$itemsLeft = number_format($itemsLeft, 0, ',', '.');
$output = $message . ', ' . sprintf($itemsLeftMessage, $itemsLeft);
echo substr($output, 0, $this->_getMaximumMessageLength());
}
} | [
"public",
"function",
"display",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"itemsLeftMessage",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_verifyTotalValue",
"(",
")",
";",
"$",
"this",
"->",
"_clearLine",
"(",
")",
";",
"$",
"this",
"->",
"_renderPr... | Output the progressbar to the screen.
@param string $message Optional message displayed next to the progress bar.
@param string $itemsLeftMessage Indicate optional remaining value position with '%s'.
If you want to use this param, provide $message as well.
@return void | [
"Output",
"the",
"progressbar",
"to",
"the",
"screen",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Ui/ProgressBar.php#L69-L82 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Ui/ProgressBar.php | Garp_Cli_Ui_ProgressBar._detectNumberOfTerminalColumns | protected function _detectNumberOfTerminalColumns() {
$terminalCols = null;
try {
exec('tput cols 2> /dev/null', $terminalCols, $errorCode);
if ($errorCode == 0 && $terminalCols && array_key_exists(0, $terminalCols)) {
return (int)$terminalCols[0];
}
} catch (Exception $e) {
}
return self::DEFAULT_SCREEN_SIZE;
} | php | protected function _detectNumberOfTerminalColumns() {
$terminalCols = null;
try {
exec('tput cols 2> /dev/null', $terminalCols, $errorCode);
if ($errorCode == 0 && $terminalCols && array_key_exists(0, $terminalCols)) {
return (int)$terminalCols[0];
}
} catch (Exception $e) {
}
return self::DEFAULT_SCREEN_SIZE;
} | [
"protected",
"function",
"_detectNumberOfTerminalColumns",
"(",
")",
"{",
"$",
"terminalCols",
"=",
"null",
";",
"try",
"{",
"exec",
"(",
"'tput cols 2> /dev/null'",
",",
"$",
"terminalCols",
",",
"$",
"errorCode",
")",
";",
"if",
"(",
"$",
"errorCode",
"==",
... | Returns the number of columns in the current terminal screen.
@return int Number of available colums | [
"Returns",
"the",
"number",
"of",
"columns",
"in",
"the",
"current",
"terminal",
"screen",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Ui/ProgressBar.php#L158-L170 | train |
grrr-amsterdam/garp3 | library/Garp/Util/AssetUrl.php | Garp_Util_AssetUrl.getRevManifest | public function getRevManifest(): array {
if (is_null(self::$_revManifest)) {
$manifestPath = APPLICATION_PATH . '/../rev-manifest-' . APPLICATION_ENV . '.json';
self::$_revManifest = file_exists($manifestPath)
? json_decode(file_get_contents($manifestPath), true)
: [];
}
return self::$_revManifest;
} | php | public function getRevManifest(): array {
if (is_null(self::$_revManifest)) {
$manifestPath = APPLICATION_PATH . '/../rev-manifest-' . APPLICATION_ENV . '.json';
self::$_revManifest = file_exists($manifestPath)
? json_decode(file_get_contents($manifestPath), true)
: [];
}
return self::$_revManifest;
} | [
"public",
"function",
"getRevManifest",
"(",
")",
":",
"array",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"_revManifest",
")",
")",
"{",
"$",
"manifestPath",
"=",
"APPLICATION_PATH",
".",
"'/../rev-manifest-'",
".",
"APPLICATION_ENV",
".",
"'.json'",
... | Read rev-manifest file, generated by a process like gulp-rev.
It maps original filenames to hashes ones.
Note that it is cached statically to be saved during the runtime of the script.
@return string | [
"Read",
"rev",
"-",
"manifest",
"file",
"generated",
"by",
"a",
"process",
"like",
"gulp",
"-",
"rev",
".",
"It",
"maps",
"original",
"filenames",
"to",
"hashes",
"ones",
".",
"Note",
"that",
"it",
"is",
"cached",
"statically",
"to",
"be",
"saved",
"duri... | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/AssetUrl.php#L116-L124 | train |
grrr-amsterdam/garp3 | library/Garp/Form/SubForm.php | Garp_Form_SubForm.createElement | public function createElement($type, $name, $options = null) {
$element = parent::createElement($type, $name, $options);
return $element;
} | php | public function createElement($type, $name, $options = null) {
$element = parent::createElement($type, $name, $options);
return $element;
} | [
"public",
"function",
"createElement",
"(",
"$",
"type",
",",
"$",
"name",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"element",
"=",
"parent",
"::",
"createElement",
"(",
"$",
"type",
",",
"$",
"name",
",",
"$",
"options",
")",
";",
"return",
... | Add index to name attribute for better organisation of POST data.
@param string $type
@param string $name
@param array|Zend_Config $options
@return Zend_Form_Element | [
"Add",
"index",
"to",
"name",
"attribute",
"for",
"better",
"organisation",
"of",
"POST",
"data",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Form/SubForm.php#L47-L50 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command.php | Garp_Cli_Command.complete | public function complete(array $args = array()) {
$publicMethods = $this->getPublicMethods();
$ignoredMethods = array('complete');
$publicMethods = array_diff($publicMethods, $ignoredMethods);
Garp_Cli::lineOut(implode(' ', $publicMethods));
return true;
} | php | public function complete(array $args = array()) {
$publicMethods = $this->getPublicMethods();
$ignoredMethods = array('complete');
$publicMethods = array_diff($publicMethods, $ignoredMethods);
Garp_Cli::lineOut(implode(' ', $publicMethods));
return true;
} | [
"public",
"function",
"complete",
"(",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"publicMethods",
"=",
"$",
"this",
"->",
"getPublicMethods",
"(",
")",
";",
"$",
"ignoredMethods",
"=",
"array",
"(",
"'complete'",
")",
";",
"$",
"publ... | Assists in bash completion
@param array $args
@return bool | [
"Assists",
"in",
"bash",
"completion"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command.php#L79-L85 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command.php | Garp_Cli_Command.getPublicMethods | public function getPublicMethods() {
$reflect = new ReflectionClass($this);
$publicMethods = $reflect->getMethods(ReflectionMethod::IS_PUBLIC);
$publicMethods = array_map(
function ($m) {
return $m->name;
},
$publicMethods
);
$publicMethods = array_filter(
$publicMethods,
function ($m) {
$ignoreMethods = array('__construct', 'main', 'getPublicMethods');
return !in_array($m, $ignoreMethods);
}
);
return $publicMethods;
} | php | public function getPublicMethods() {
$reflect = new ReflectionClass($this);
$publicMethods = $reflect->getMethods(ReflectionMethod::IS_PUBLIC);
$publicMethods = array_map(
function ($m) {
return $m->name;
},
$publicMethods
);
$publicMethods = array_filter(
$publicMethods,
function ($m) {
$ignoreMethods = array('__construct', 'main', 'getPublicMethods');
return !in_array($m, $ignoreMethods);
}
);
return $publicMethods;
} | [
"public",
"function",
"getPublicMethods",
"(",
")",
"{",
"$",
"reflect",
"=",
"new",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"$",
"publicMethods",
"=",
"$",
"reflect",
"->",
"getMethods",
"(",
"ReflectionMethod",
"::",
"IS_PUBLIC",
")",
";",
"$",
"p... | Return a list of all public methods available on this command.
@return array | [
"Return",
"a",
"list",
"of",
"all",
"public",
"methods",
"available",
"on",
"this",
"command",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command.php#L92-L109 | train |
grrr-amsterdam/garp3 | library/Garp/Cli/Command.php | Garp_Cli_Command._validateArguments | protected function _validateArguments($methodName, $args) {
if (!array_key_exists($methodName, $this->_allowedArguments)
|| $this->_allowedArguments[$methodName] === '*'
) {
return true;
}
$unknownArgs = array_diff(array_keys($args), $this->_allowedArguments[$methodName]);
if (!count($unknownArgs)) {
return true;
}
// Report the first erroneous argument
$errorStr = current($unknownArgs);
// Show the value of the argument if the index is numeric
if (is_numeric($errorStr)) {
$errorStr = $args[$unknownArgs[0]];
}
Garp_Cli::errorOut('Unexpected argument ' . $errorStr);
return false;
} | php | protected function _validateArguments($methodName, $args) {
if (!array_key_exists($methodName, $this->_allowedArguments)
|| $this->_allowedArguments[$methodName] === '*'
) {
return true;
}
$unknownArgs = array_diff(array_keys($args), $this->_allowedArguments[$methodName]);
if (!count($unknownArgs)) {
return true;
}
// Report the first erroneous argument
$errorStr = current($unknownArgs);
// Show the value of the argument if the index is numeric
if (is_numeric($errorStr)) {
$errorStr = $args[$unknownArgs[0]];
}
Garp_Cli::errorOut('Unexpected argument ' . $errorStr);
return false;
} | [
"protected",
"function",
"_validateArguments",
"(",
"$",
"methodName",
",",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"methodName",
",",
"$",
"this",
"->",
"_allowedArguments",
")",
"||",
"$",
"this",
"->",
"_allowedArguments",
"["... | Make sure the method is not inadvertently called with the
wrong arguments. This might indicate the user made a mistake
in calling it.
@param string $methodName
@param array $args
@return bool | [
"Make",
"sure",
"the",
"method",
"is",
"not",
"inadvertently",
"called",
"with",
"the",
"wrong",
"arguments",
".",
"This",
"might",
"indicate",
"the",
"user",
"made",
"a",
"mistake",
"in",
"calling",
"it",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command.php#L152-L171 | train |
grrr-amsterdam/garp3 | library/Garp/Form/SubForm/Array.php | Garp_Form_SubForm_Array.isValid | public function isValid($data) {
if (!is_array($data)) {
throw new Zend_Form_Exception(__METHOD__ . ' expects an array');
}
$this->_incrementArray($data);
return parent::isValid($data);
} | php | public function isValid($data) {
if (!is_array($data)) {
throw new Zend_Form_Exception(__METHOD__ . ' expects an array');
}
$this->_incrementArray($data);
return parent::isValid($data);
} | [
"public",
"function",
"isValid",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"Zend_Form_Exception",
"(",
"__METHOD__",
".",
"' expects an array'",
")",
";",
"}",
"$",
"this",
"->",
"_incrementA... | Upon validation, we can check if there have been dynamically added input
fields, and if so, create elements for them.
@return Boolean | [
"Upon",
"validation",
"we",
"can",
"check",
"if",
"there",
"have",
"been",
"dynamically",
"added",
"input",
"fields",
"and",
"if",
"so",
"create",
"elements",
"for",
"them",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Form/SubForm/Array.php#L83-L90 | train |
grrr-amsterdam/garp3 | library/Garp/Form/SubForm/Array.php | Garp_Form_SubForm_Array._createSubFormAtIndex | protected function _createSubFormAtIndex($index) {
$class = 'garp-subform';
if ($this->isDuplicatable()) {
$class .= ' duplicatable';
}
$subform = new Garp_Form_SubForm(array(
'name' => (string)$index,
'class' => $class
));
if (is_array($this->_duplicatableOptions)) {
if (!empty($this->_duplicatableOptions['buttonClass'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-class', $this->_duplicatableOptions['buttonClass']);
}
if (!empty($this->_duplicatableOptions['buttonAddClass'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-add-class', $this->_duplicatableOptions['buttonAddClass']);
}
if (!empty($this->_duplicatableOptions['buttonRemoveClass'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-remove-class', $this->_duplicatableOptions['buttonRemoveClass']);
}
if (!empty($this->_duplicatableOptions['buttonAddLabel'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-add-text', $this->_duplicatableOptions['buttonAddLabel']);
}
if (!empty($this->_duplicatableOptions['buttonRemoveLabel'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-remove-text', $this->_duplicatableOptions['buttonRemoveLabel']);
}
if (!empty($this->_duplicatableOptions['skipElements'])) {
$subform->getDecorator('HtmlTag')->setOption('data-skip-elements', $this->_duplicatableOptions['skipElements']);
}
if (!empty($this->_duplicatableOptions['afterDuplicate'])) {
$subform->getDecorator('HtmlTag')->setOption('data-after-duplicate', $this->_duplicatableOptions['afterDuplicate']);
}
}
return $subform;
} | php | protected function _createSubFormAtIndex($index) {
$class = 'garp-subform';
if ($this->isDuplicatable()) {
$class .= ' duplicatable';
}
$subform = new Garp_Form_SubForm(array(
'name' => (string)$index,
'class' => $class
));
if (is_array($this->_duplicatableOptions)) {
if (!empty($this->_duplicatableOptions['buttonClass'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-class', $this->_duplicatableOptions['buttonClass']);
}
if (!empty($this->_duplicatableOptions['buttonAddClass'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-add-class', $this->_duplicatableOptions['buttonAddClass']);
}
if (!empty($this->_duplicatableOptions['buttonRemoveClass'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-remove-class', $this->_duplicatableOptions['buttonRemoveClass']);
}
if (!empty($this->_duplicatableOptions['buttonAddLabel'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-add-text', $this->_duplicatableOptions['buttonAddLabel']);
}
if (!empty($this->_duplicatableOptions['buttonRemoveLabel'])) {
$subform->getDecorator('HtmlTag')->setOption('data-button-remove-text', $this->_duplicatableOptions['buttonRemoveLabel']);
}
if (!empty($this->_duplicatableOptions['skipElements'])) {
$subform->getDecorator('HtmlTag')->setOption('data-skip-elements', $this->_duplicatableOptions['skipElements']);
}
if (!empty($this->_duplicatableOptions['afterDuplicate'])) {
$subform->getDecorator('HtmlTag')->setOption('data-after-duplicate', $this->_duplicatableOptions['afterDuplicate']);
}
}
return $subform;
} | [
"protected",
"function",
"_createSubFormAtIndex",
"(",
"$",
"index",
")",
"{",
"$",
"class",
"=",
"'garp-subform'",
";",
"if",
"(",
"$",
"this",
"->",
"isDuplicatable",
"(",
")",
")",
"{",
"$",
"class",
".=",
"' duplicatable'",
";",
"}",
"$",
"subform",
... | Create a new subform at a given index
@param Int $index
@return Garp_SubForm | [
"Create",
"a",
"new",
"subform",
"at",
"a",
"given",
"index"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Form/SubForm/Array.php#L138-L171 | train |
grrr-amsterdam/garp3 | library/Garp/Service/Bitly.php | Garp_Service_Bitly.shorten | public function shorten(array $params) {
$params = $params instanceof Garp_Util_Configuration ? $params : new Garp_Util_Configuration($params);
$params->obligate('longUrl');
return $this->request('shorten', (array)$params);
} | php | public function shorten(array $params) {
$params = $params instanceof Garp_Util_Configuration ? $params : new Garp_Util_Configuration($params);
$params->obligate('longUrl');
return $this->request('shorten', (array)$params);
} | [
"public",
"function",
"shorten",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"params",
"=",
"$",
"params",
"instanceof",
"Garp_Util_Configuration",
"?",
"$",
"params",
":",
"new",
"Garp_Util_Configuration",
"(",
"$",
"params",
")",
";",
"$",
"params",
"->",
... | Shorten a URL
@param Array $params
@return stdClass | [
"Shorten",
"a",
"URL"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Bitly.php#L64-L68 | train |
grrr-amsterdam/garp3 | library/Garp/Form/Element/Text.php | Garp_Form_Element_Text._getType | protected function _getType() {
$className = strtolower(get_class($this));
$classNameParts = explode('_', $className);
$type = array_pop($classNameParts);
if (array_key_exists($type, self::$_mapping)) {
return self::$_mapping[$type];
}
return self::DEFAULT_TYPE;
} | php | protected function _getType() {
$className = strtolower(get_class($this));
$classNameParts = explode('_', $className);
$type = array_pop($classNameParts);
if (array_key_exists($type, self::$_mapping)) {
return self::$_mapping[$type];
}
return self::DEFAULT_TYPE;
} | [
"protected",
"function",
"_getType",
"(",
")",
"{",
"$",
"className",
"=",
"strtolower",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"classNameParts",
"=",
"explode",
"(",
"'_'",
",",
"$",
"className",
")",
";",
"$",
"type",
"=",
"array_pop... | Take the type from the classname
@return String | [
"Take",
"the",
"type",
"from",
"the",
"classname"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Form/Element/Text.php#L81-L89 | train |
grrr-amsterdam/garp3 | library/Garp/Model/Behavior/Authorable.php | Garp_Model_Behavior_Authorable.beforeFetch | public function beforeFetch(array &$args) {
$model = $args[0];
$select = &$args[1];
if (!$model->isCmsContext()) {
return;
}
if (!Garp_Auth::getInstance()->isAllowed(get_class($model), 'fetch')
&& Garp_Auth::getInstance()->isAllowed(get_class($model), 'fetch_own')
) {
$currentUserData = Garp_Auth::getInstance()->getUserData();
$currentUserId = $currentUserData['id'];
$select->where(self::_AUTHOR_COLUMN . ' = ?', $currentUserId);
}
} | php | public function beforeFetch(array &$args) {
$model = $args[0];
$select = &$args[1];
if (!$model->isCmsContext()) {
return;
}
if (!Garp_Auth::getInstance()->isAllowed(get_class($model), 'fetch')
&& Garp_Auth::getInstance()->isAllowed(get_class($model), 'fetch_own')
) {
$currentUserData = Garp_Auth::getInstance()->getUserData();
$currentUserId = $currentUserData['id'];
$select->where(self::_AUTHOR_COLUMN . ' = ?', $currentUserId);
}
} | [
"public",
"function",
"beforeFetch",
"(",
"array",
"&",
"$",
"args",
")",
"{",
"$",
"model",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"select",
"=",
"&",
"$",
"args",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"$",
"model",
"->",
"isCmsContext",
"("... | Before fetch callback.
@param array $args
@return void | [
"Before",
"fetch",
"callback",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Authorable.php#L22-L35 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/Js/Model/File/Abstract.php | Garp_Spawn_Js_Model_File_Abstract._ensurePathExistence | protected function _ensurePathExistence($filePath) {
$folders = explode(DIRECTORY_SEPARATOR, $filePath);
// discard the actual file
array_pop($folders);
$path = implode(DIRECTORY_SEPARATOR, $folders);
if (file_exists($path)) {
return;
}
mkdir($path, 0777, true);
} | php | protected function _ensurePathExistence($filePath) {
$folders = explode(DIRECTORY_SEPARATOR, $filePath);
// discard the actual file
array_pop($folders);
$path = implode(DIRECTORY_SEPARATOR, $folders);
if (file_exists($path)) {
return;
}
mkdir($path, 0777, true);
} | [
"protected",
"function",
"_ensurePathExistence",
"(",
"$",
"filePath",
")",
"{",
"$",
"folders",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"filePath",
")",
";",
"// discard the actual file",
"array_pop",
"(",
"$",
"folders",
")",
";",
"$",
"path",
... | Make sure the directory structure exists before writing the file
@return Void | [
"Make",
"sure",
"the",
"directory",
"structure",
"exists",
"before",
"writing",
"the",
"file"
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Js/Model/File/Abstract.php#L42-L51 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/MySql/Table/Factory.php | Garp_Spawn_MySql_Table_Factory.produceConfigTable | public function produceConfigTable() {
$model = $this->getModel();
$createStatement = $this->_renderCreateFromConfig();
return $this->_produceTable($createStatement);
} | php | public function produceConfigTable() {
$model = $this->getModel();
$createStatement = $this->_renderCreateFromConfig();
return $this->_produceTable($createStatement);
} | [
"public",
"function",
"produceConfigTable",
"(",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
";",
"$",
"createStatement",
"=",
"$",
"this",
"->",
"_renderCreateFromConfig",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_produceTabl... | Produces a Garp_Spawn_MySql_Table_Abstract instance, based on the spawn configuration. | [
"Produces",
"a",
"Garp_Spawn_MySql_Table_Abstract",
"instance",
"based",
"on",
"the",
"spawn",
"configuration",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/MySql/Table/Factory.php#L24-L28 | train |
grrr-amsterdam/garp3 | library/Garp/Spawn/MySql/Table/Factory.php | Garp_Spawn_MySql_Table_Factory.produceLiveTable | public function produceLiveTable() {
$model = $this->getModel();
$createStatement = $this->_renderCreateFromLive();
return $this->_produceTable($createStatement);
} | php | public function produceLiveTable() {
$model = $this->getModel();
$createStatement = $this->_renderCreateFromLive();
return $this->_produceTable($createStatement);
} | [
"public",
"function",
"produceLiveTable",
"(",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
";",
"$",
"createStatement",
"=",
"$",
"this",
"->",
"_renderCreateFromLive",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_produceTable",
... | Produces a Garp_Spawn_MySql_Table_Abstract instance, based on the live database. | [
"Produces",
"a",
"Garp_Spawn_MySql_Table_Abstract",
"instance",
"based",
"on",
"the",
"live",
"database",
"."
] | ee6fa716406047568bc5227670748d3b1dd7290d | https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/MySql/Table/Factory.php#L33-L37 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.