/** * Constructs a book dialog * $action - GET or POST action to take. * $inclusions - NULL (in which case it does nothing), or an array of book IDs to include. * $exclusions - NULL (in which case it does nothing), or an array of book IDs to exclude. */ public function __construct($header, $info_top, $info_bottom, $action, $inclusions, $exclusions) { $this->view = new Assets_View(__FILE__); $caller = $_SERVER["PHP_SELF"] . "?" . http_build_query(array()); $this->view->view->caller = $caller; $this->view->view->header = $header; $this->view->view->info_top = $info_top; $this->view->view->info_bottom = $info_bottom; $this->view->view->action = $action; $database_books = Database_Books::getInstance(); $book_ids = $database_books->getIDs(); if (is_array($inclusions)) { $book_ids = $inclusions; } if (is_array($exclusions)) { $book_ids = array_diff($book_ids, $exclusions); $book_ids = array_values($book_ids); } foreach ($book_ids as $id) { $book_names[] = $database_books->getEnglishFromId($id); } $this->view->view->book_ids = $book_ids; $this->view->view->book_names = $book_names; $this->view->render("books2.php"); Assets_Page::footer(); die; }
/** * @param mixed $in */ public function __construct($in = null) { $fields = array('to', 'cc', 'bcc', 'message', 'body', 'subject'); if (is_string($in)) { if (($pos = strpos($in, '?')) !== false) { parse_str(substr($in, $pos + 1), $this->args); $this->args['to'] = substr($in, 0, $pos); } else { $this->args['to'] = $in; } } elseif ($in instanceof Horde_Variables) { foreach ($fields as $val) { if (isset($in->{$val})) { $this->args[$val] = $in->{$val}; } } } elseif (is_array($in)) { $this->args = $in; } if (isset($this->args['to']) && strpos($this->args['to'], 'mailto:') === 0) { $mailto = @parse_url($this->args['to']); if (is_array($mailto)) { $this->args['to'] = isset($mailto['path']) ? $mailto['path'] : ''; if (!empty($mailto['query'])) { parse_str($mailto['query'], $vals); foreach ($fields as $val) { if (isset($vals[$val])) { $this->args[$val] = $vals[$val]; } } } } } }
function qqwb_env() { $msgs = array(); $files = array(ROOT_PATH . 'include/ext/qqwb/qqoauth.php', ROOT_PATH . 'include/ext/qqwb/oauth.php', ROOT_PATH . 'modules/qqwb.mod.php'); foreach ($files as $f) { if (!is_file($f)) { $msgs[] = "文件<b>{$f}</b>不存在"; } } $funcs = array('version_compare', array('fsockopen', 'pfsockopen'), 'preg_replace', array('iconv', 'mb_convert_encoding'), array("hash_hmac", "mhash")); foreach ($funcs as $func) { if (!is_array($func)) { if (!function_exists($func)) { $msgs[] = "函数<b>{$func}</b>不可用"; } } else { $t = false; foreach ($func as $f) { if (function_exists($f)) { $t = true; break; } } if (!$t) { $msgs[] = "函数<b>" . implode(" , ", $func) . "</b>都不可用"; } } } return $msgs; }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $m = $this->getConfig('methods'); if (@count($m) == 1) { $a = new Am_Paysystem_Action_Form(self::URL . $m[0] . '/event/'); } else { $a = new Am_Paysystem_Action_HtmlTemplate_Micropayment($this->getDir(), 'micropayment-confirm.phtml'); $methods = array(); if (@count($m)) { $a->url = self::URL . $m[0] . '/event/'; foreach ($m as $title) { $methods[self::URL . $title . '/event/'] = $this->getConfig($title . '.title'); } } else { foreach ($this->getConfig() as $k => $v) { if (is_array($v) && !empty($v['title'])) { $methods[self::URL . $k . '/event/'] = $v['title']; } } $a->url = array_shift(array_keys($methods)); } $a->methods = $methods; } $a->project = $this->getConfig('project'); $a->amount = $invoice->first_total * 100; $a->freepaymentid = $invoice->public_id; $a->seal = md5("project={$a->project}&amount={$a->amount}&freepaymentid={$a->freepaymentid}" . $this->getConfig('key')); $result->setAction($a); }
protected function getInput() { if (!NNFrameworkFunctions::extensionInstalled('virtuemart')) { return '<fieldset class="alert alert-danger">' . JText::_('ERROR') . ': ' . JText::sprintf('NN_FILES_NOT_FOUND', JText::_('NN_VIRTUEMART')) . '</fieldset>'; } $this->params = $this->element->attributes(); $this->db = JFactory::getDBO(); $group = $this->get('group', 'categories'); $tables = $this->db->getTableList(); if (!in_array($this->db->getPrefix() . 'virtuemart_' . $group, $tables)) { return '<fieldset class="alert alert-danger">' . JText::_('ERROR') . ': ' . JText::sprintf('NN_TABLE_NOT_FOUND', JText::_('NN_VIRTUEMART')) . '</fieldset>'; } $parameters = NNParameters::getInstance(); $params = $parameters->getPluginParams('nnframework'); $this->max_list_count = $params->max_list_count; if (!is_array($this->value)) { $this->value = explode(',', $this->value); } $options = $this->{'get' . $group}(); $size = (int) $this->get('size'); $multiple = $this->get('multiple'); if ($group == 'categories') { require_once JPATH_PLUGINS . '/system/nnframework/helpers/html.php'; return nnHtml::selectlist($options, $this->name, $this->value, $this->id, $size, $multiple); } $attr = ''; $attr .= ' size="' . (int) $size . '"'; $attr .= $multiple ? ' multiple="multiple"' : ''; return JHtml::_('select.genericlist', $options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id); }
/** * Assert that after deleting product success message. * * @param FixtureInterface|FixtureInterface[] $product * @param CatalogProductIndex $productPage * @return void */ public function processAssert($product, CatalogProductIndex $productPage) { $products = is_array($product) ? $product : [$product]; $deleteMessage = sprintf(self::SUCCESS_DELETE_MESSAGE, count($products)); $actualMessage = $productPage->getMessagesBlock()->getSuccessMessage(); \PHPUnit_Framework_Assert::assertEquals($deleteMessage, $actualMessage, 'Wrong success message is displayed.' . "\nExpected: " . $deleteMessage . "\nActual: " . $actualMessage); }
/** @return object */ public static function getSwarmUAIndex() { // Lazy-init and cache if (self::$swarmUaIndex === null) { global $swarmInstallDir; // Convert from array with string values // to an object with boolean values $swarmUaIndex = new stdClass(); $rawIndex = parse_ini_file("{$swarmInstallDir}/config/useragents.ini", true); foreach ($rawIndex as $uaID => $uaItem) { if (is_array($uaItem)) { $uaItem2 = $uaItem; foreach ($uaItem2 as $uaDataKey => $uaDataVal) { if ($uaDataKey !== "displaytitle" && $uaDataKey !== "displayicon") { $uaItem[$uaDataKey] = (bool) trim($uaDataVal); } else { $uaItem[$uaDataKey] = trim($uaDataVal); } } if (!isset($uaItem["displaytitle"]) || !$uaItem["displaytitle"]) { throw new SwarmException("User agent `{$uaID}` is missing a displaytitle property."); } if (!isset($uaItem["displayicon"]) || !$uaItem["displayicon"]) { throw new SwarmException("User agent `{$uaID}` is missing a displayicon property."); } $swarmUaIndex->{$uaID} = (object) $uaItem; } } self::$swarmUaIndex = $swarmUaIndex; } return self::$swarmUaIndex; }
/** * Return a OpenSeadragon image viewer for the provided files. * * @param File|array $files A File record or an array of File records. * @param int $width The width of the image viewer in pixels. * @param int $height The height of the image viewer in pixels. * @return string|null */ public function openseadragon($files) { if (!is_array($files)) { $files = array($files); } // Filter out invalid images. $images = array(); $imageNames = array(); foreach ($files as $file) { // A valid image must be a File record. if (!$file instanceof File) { continue; } // A valid image must have a supported extension. $extension = pathinfo($file->original_filename, PATHINFO_EXTENSION); if (!in_array(strtolower($extension), $this->_supportedExtensions)) { continue; } $images[] = $file; $imageNames[explode(".", $file->filename)[0]] = openseadragon_dimensions($file, 'original'); } // Return if there are no valid images. if (!$images) { return; } return $this->view->partial('common/openseadragon.php', array('images' => $images, 'imageNames' => $imageNames)); }
/** * {@inheritdoc} */ public function apply(DataSourceInterface $dataSource, $name, $data, array $options) { $expressionBuilder = $dataSource->getExpressionBuilder(); if (is_array($data) && !isset($data['type'])) { $data['type'] = isset($options['type']) ? $options['type'] : self::TYPE_CONTAINS; } if (!is_array($data)) { $data = ['type' => self::TYPE_CONTAINS, 'value' => $data]; } $fields = array_key_exists('fields', $options) ? $options['fields'] : [$name]; $type = $data['type']; $value = array_key_exists('value', $data) ? $data['value'] : null; if (!in_array($type, [self::TYPE_NOT_EMPTY, self::TYPE_EMPTY], true) && '' === trim($value)) { return; } if (1 === count($fields)) { $dataSource->restrict($this->getExpression($expressionBuilder, $type, current($fields), $value)); return; } $expressions = []; foreach ($fields as $field) { $expressions[] = $this->getExpression($expressionBuilder, $type, $field, $value); } $dataSource->restrict($expressionBuilder->orX(...$expressions)); }
/** * Get value that should be validated. * * @param mixed $value * @return mixed */ protected function _getValidatorValue($value) { if (is_array($value)) { $value = new \Magento\Framework\DataObject($value); } return $value; }
/** * Generates a 'List' element. * * @param array $items Array with the elements of the list * @param boolean $ordered Specifies ordered/unordered list; default unordered * @param array $attribs Attributes for the ol/ul tag. * @return string The list XHTML. */ public function htmlList(array $items, $ordered = false, $attribs = false, $escape = true) { if (!is_array($items)) { #require_once 'Zend/View/Exception.php'; $e = new Zend_View_Exception('First param must be an array'); $e->setView($this->view); throw $e; } $list = ''; foreach ($items as $item) { if (!is_array($item)) { if ($escape) { $item = $this->view->escape($item); } $list .= '<li>' . $item . '</li>' . self::EOL; } else { if (6 < strlen($list)) { $list = substr($list, 0, strlen($list) - 6) . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL; } else { $list .= '<li>' . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL; } } } if ($attribs) { $attribs = $this->_htmlAttribs($attribs); } else { $attribs = ''; } $tag = 'ul'; if ($ordered) { $tag = 'ol'; } return '<' . $tag . $attribs . '>' . self::EOL . $list . '</' . $tag . '>' . self::EOL; }
public static function convertDateMomentToPhp($format) { $tokens = ["M" => "n", "Mo" => "nS", "MM" => "m", "MMM" => "M", "MMMM" => "F", "D" => "j", "Do" => "jS", "DD" => "d", "DDD" => "z", "DDDo" => "zS", "DDDD" => "zS", "d" => "w", "do" => "wS", "dd" => "D", "ddd" => "D", "dddd" => "l", "e" => "w", "E" => "N", "w" => "W", "wo" => "WS", "ww" => "W", "W" => "W", "Wo" => "WS", "WW" => "W", "YY" => "y", "YYYY" => "Y", "gg" => "o", "gggg" => "o", "GG" => "o", "GGGG" => "o", "A" => "A", "a" => "a", "H" => "G", "HH" => "H", "h" => "g", "hh" => "h", "m" => "i", "mm" => "i", "s" => "s", "ss" => "s", "S" => "", "SS" => "", "SSS" => "", "z or zz" => "T", "Z" => "P", "ZZ" => "O", "X" => "U", "LT" => "g:i A", "L" => "m/d/Y", "l" => "n/j/Y", "LL" => "F jS Y", "ll" => "M j Y", "LLL" => "F js Y g:i A", "lll" => "M j Y g:i A", "LLLL" => "l, F jS Y g:i A", "llll" => "D, M j Y g:i A"]; // find all tokens from string, using regular expression $regExp = "/(\\[[^\\[]*\\])|(\\\\)?(LT|LL?L?L?|l{1,4}|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/"; $matches = array(); preg_match_all($regExp, $format, $matches); // if there is no match found then return the string as it is // TODO: might return escaped string if (empty($matches) || is_array($matches) === false) { return $format; } // to match with extracted tokens $momentTokens = array_keys($tokens); $phpMatches = array(); // ---------------------------------- foreach ($matches[0] as $id => $match) { // if there is a matching php token in token list if (in_array($match, $momentTokens)) { // use the php token instead $string = $tokens[$match]; } else { $string = $match; } $phpMatches[$id] = $string; } // join and return php specific tokens return implode("", $phpMatches); }
/** * @param array $fields * @return array|null */ public static function getEndpointFromFields(array $fields) { $arEndpointList = null; $fieldsTmp = array(); foreach ($fields as $moduleId => $arConnectorSettings) { if (is_numeric($moduleId)) { $moduleId = ''; } foreach ($arConnectorSettings as $connectorCode => $arConnectorFields) { foreach ($arConnectorFields as $k => $arFields) { if (isset($fieldsTmp[$moduleId][$connectorCode][$k]) && is_array($arFields)) { $fieldsTmp[$moduleId][$connectorCode][$k] = array_merge($fieldsTmp[$moduleId][$connectorCode][$k], $arFields); } else { $fieldsTmp[$moduleId][$connectorCode][$k] = $arFields; } } } } foreach ($fieldsTmp as $moduleId => $arConnectorSettings) { if (is_numeric($moduleId)) { $moduleId = ''; } foreach ($arConnectorSettings as $connectorCode => $arConnectorFields) { foreach ($arConnectorFields as $arFields) { $arEndpoint = array(); $arEndpoint['MODULE_ID'] = $moduleId; $arEndpoint['CODE'] = $connectorCode; $arEndpoint['FIELDS'] = $arFields; $arEndpointList[] = $arEndpoint; } } } return $arEndpointList; }
public function fetch_all($cachenames, $lv) { global $_G; $data = array(); if ($lv > 1 && !$cachenames) { $cachenames = $_G[_config][cache_list]; } if (defined('DEBUG')) { $name = $this->obj->name; if (in_array($name, array('memcache', 'baichuan'))) { $_G['memory_debug']['get'] = array(); if (is_array($cachenames)) { $_G['memory_debug']['get'] = $cachenames; } else { $_G['memory_debug']['get'][] = $key; } } } $data = $this->obj->get($cachenames); if ($data === false || $data === NULL) { $this->update($cachenames); } if (is_array($cachenames)) { foreach ($data as $k => $v) { if ($v === false) { $data[$k] = $this->update($k); } } } return $data; }
/** * * Sanitizes a file-upload information array. If no file has been * uploaded, the information will be returned as null. * * @param array $value An array of file-upload information. * * @return mixed The sanitized upload information array, or null. * */ public function sanitizeUpload($value) { // if the value is not required, and is blank, sanitize to null $null = !$this->_filter->getRequire() && $this->_filter->validateBlank($value); if ($null) { return null; } // has to be an array if (!is_array($value)) { return null; } // presorted list of expected keys $expect = array('error', 'name', 'size', 'tmp_name', 'type'); // remove unexpected keys foreach ($value as $key => $val) { if (!in_array($key, $expect)) { unset($value[$key]); } } // sort the list of remaining actual keys $actual = array_keys($value); sort($actual); // make sure the expected and actual keys match up if ($expect != $actual) { return null; } // if all the non-error values are empty, still null $empty = empty($value['name']) && empty($value['size']) && empty($value['tmp_name']) && empty($value['type']); if ($empty) { return null; } // everything looks ok, return as-is return $value; }
/** * Configure a new connection object. * * The connection will not be constructed until it is first used. * * @see \Cake\Core\StaticConfigTrait::config() * * @param string|array $key The name of the connection config, or an array of multiple configs. * @param array $config An array of name => config data for adapter. * @return mixed null when adding configuration and an array of configuration data when reading. * @throws \Cake\Error\Exception When trying to modify an existing config. */ public static function config($key, $config = null) { if (is_array($config)) { $config['name'] = $key; } return static::_config($key, $config); }
function voiceemail_check_backup_mods($course, $user_data = false, $backup_unique_code, $instances = null) { if (!empty($instances) && is_array($instances) && count($instances)) { $info = array(); foreach ($instances as $id => $instance) { $info += voiceemail_check_backup_mods_instances($instance, $backup_unique_code); } return $info; } //First the course data $info[0][0] = get_string("modulenameplural", "voiceemail"); if ($ids = voiceemail_ids($course)) { $info[0][1] = count($ids); } else { $info[0][1] = 0; } //Now, if requested, the user_data // if ($user_data) { // $info[1][0] = get_string("messages","voiceemail"); // if ($ids = voiceemail_message_ids_by_course ($course)) { // $info[1][1] = count($ids); // } else { // $info[1][1] = 0; //} //} return $info; }
/** * ArtifactFile - constructor. * * @param object The Artifact object. * @param array (all fields from artifact_file_user_vw) OR id from database. * @return boolean success. */ function ArtifactFile(&$Artifact, $data = false) { global $Language; $this->Error(); //was Artifact legit? if (!$Artifact || !is_object($Artifact)) { $this->setError('ArtifactFile: ' . $Language->getText('tracker_common_file', 'invalid')); return false; } //did ArtifactType have an error? if ($Artifact->isError()) { $this->setError('ArtifactFile: ' . $Artifact->getErrorMessage()); return false; } $this->Artifact = $Artifact; if ($data) { if (is_array($data)) { $this->data_array = $data; return true; } else { if (!$this->fetchData($data)) { return false; } else { return true; } } } }
/** * Validate the provided value or list of values against the criterion. * * @since 0.4 * * @param Parameter $parameter * @param array $parameters * * @return CriterionValidationResult */ public function validate(Parameter $parameter, array $parameters) { $result = new CriterionValidationResult(); if (is_array($parameter->getValue())) { foreach ($parameter->getValue() as $item) { if (!$this->doValidation($item, $parameter, $parameters)) { $result->addInvalidItem($item); } } if ($result->hasInvalidItems()) { $allInvalid = count($result->getInvalidItems()) == count($parameter->getValue()); // If the parameter is required and all items are invalid, it's fatal. // Else it's high for required, and normal for non-required parameters. if ($parameter->isRequired()) { $severity = $allInvalid ? ValidationError::SEVERITY_FATAL : ValidationError::SEVERITY_HIGH; } else { $severity = $allInvalid ? ValidationError::SEVERITY_NORMAL : ValidationError::SEVERITY_LOW; } $result->addError(new ValidationError($this->getListErrorMessage($parameter, $result->getInvalidItems(), $allInvalid), $severity)); } } else { if (!$this->doValidation($parameter->getValue(), $parameter, $parameters)) { $result->addError(new ValidationError($this->getItemErrorMessage($parameter), $parameter->isRequired() ? ValidationError::SEVERITY_FATAL : ValidationError::SEVERITY_NORMAL)); } } return $result; }
public function batchAction() { if (!$this->request->isPut()) { return $this->showErrorMessageAsJson(405, 'ERR_REQUEST_METHOD_NOT_ALLOW'); } $idArray = $this->request->getPut('id'); if (!is_array($idArray) || count($idArray) < 1) { return $this->showErrorMessageAsJson(401, 'ERR_REQUEST_PARAMS_INCORRECT'); } $status = $this->request->getPut('status'); $comments = array(); $commentManager = new Models\CommentManager(); try { foreach ($idArray as $id) { $comment = $commentManager->findCommentById($id); if ($comment) { $commentManager->updateCommentStatus($comment, $status); $comments[] = $comment; } } } catch (\Exception $e) { return $this->showExceptionAsJson($e, $comment->getMessages()); } return $this->response->setJsonContent($comments); }
function content_56655ccb038d51_05727181($_smarty_tpl) { ?> <div class="tree-actions pull-right"> <?php if (isset($_smarty_tpl->tpl_vars['actions']->value)) { ?> <?php $_smarty_tpl->tpl_vars['action'] = new Smarty_Variable(); $_smarty_tpl->tpl_vars['action']->_loop = false; $_from = $_smarty_tpl->tpl_vars['actions']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars['action']->key => $_smarty_tpl->tpl_vars['action']->value) { $_smarty_tpl->tpl_vars['action']->_loop = true; ?> <?php echo $_smarty_tpl->tpl_vars['action']->value->render(); ?> <?php } ?> <?php } ?> </div><?php }
public function unserialize($value, ClassMetadata $metadata, $field) { $array = array(); $serializerMetadata = $metadata->getSerializer(); //reset value to array if (!is_array($value)) { if ($value instanceof ArrayCollection) { $value = $value->toArray(); } elseif ($value instanceof ArrayObject) { $value = $value->getArrayCopy(); } } if (isset($serializerMetadata['fields'][$field]['collectionType'])) { switch ($serializerMetadata['fields'][$field]['collectionType']) { case 'ArrayObject': $array = new ArrayObject($value); break; case 'ArrayCollection': $array = new ArrayCollection($value); break; case 'Array': case 'array': default: $array = $value; break; } } else { $array = (array) $value; } return $array; }
function load($tpl_view, $body_view = null, $data = null) { if (!is_null($body_view)) { if (file_exists(APPPATH . 'views/' . $tpl_view . '/' . $body_view)) { $body_view_path = $tpl_view . '/' . $body_view; } else { if (file_exists(APPPATH . 'views/' . $tpl_view . '/' . $body_view . '.php')) { $body_view_path = $tpl_view . '/' . $body_view . '.php'; } else { if (file_exists(APPPATH . 'views/' . $body_view)) { $body_view_path = $body_view; } else { if (file_exists(APPPATH . 'views/' . $body_view . '.php')) { $body_view_path = $body_view . '.php'; } else { show_error('Unable to load the requested file: ' . $tpl_name . '/' . $view_name . '.php'); } } } } $body = $this->ci->load->view($body_view_path, $data, TRUE); if (is_null($data)) { $data = array('body' => $body); } else { if (is_array($data)) { $data['body'] = $body; } else { if (is_object($data)) { $data->body = $body; } } } } $this->ci->load->view('templates/' . $tpl_view, $data); }
/** * Constructor. * * @param mixed $value The value to mark as safe */ public function __construct($value) { $this->value = $value; if (is_array($value) || is_object($value)) { parent::__construct($value); } }
/** * This is the model class for table "dcmd_task_template". * * @property integer $task_tmpt_id * @property string $task_tmpt_name * @property integer $task_cmd_id * @property string $task_cmd * @property integer $svr_id * @property string $svr_name * @property integer $app_id * @property integer $update_env * @property integer $concurrent_rate * @property integer $timeout * @property integer $process * @property integer $auto * @property string $task_arg * @property string $comment * @property string $utime * @property string $ctime * @property integer $opr_uid */ function xml_to_array($xml) { //array(1) { ["env"]=> array(2) { ["name"]=> string(2) "gu" ["aa"]=> string(4) "miao" } } $reg = "/<(\\w+)[^>]*?>([\\x00-\\xFF]*?)<\\/\\1>/"; if (preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); $arr = array(); for ($i = 0; $i < $count; $i++) { $key = $matches[1][$i]; $val = xml_to_array($matches[2][$i]); // 递归 if (array_key_exists($key, $arr)) { if (is_array($arr[$key])) { if (!array_key_exists(0, $arr[$key])) { $arr[$key] = array($arr[$key]); } } else { $arr[$key] = array($arr[$key]); } $arr[$key][] = $val; } else { $arr[$key] = $val; } } return $arr; } else { return $xml; } }
public function createCommand(TaskInfo $taskInfo) { $task = new Command($taskInfo->getName()); $task->setDescription($taskInfo->getDescription()); $task->setHelp($taskInfo->getHelp()); $args = $taskInfo->getArguments(); foreach ($args as $name => $val) { $description = $taskInfo->getArgumentDescription($name); if ($val === TaskInfo::PARAM_IS_REQUIRED) { $task->addArgument($name, InputArgument::REQUIRED, $description); } elseif (is_array($val)) { $task->addArgument($name, InputArgument::IS_ARRAY, $description, $val); } else { $task->addArgument($name, InputArgument::OPTIONAL, $description, $val); } } $opts = $taskInfo->getOptions(); foreach ($opts as $name => $val) { $description = $taskInfo->getOptionDescription($name); $fullName = $name; $shortcut = ''; if (strpos($name, '|')) { list($fullName, $shortcut) = explode('|', $name, 2); } if (is_bool($val)) { $task->addOption($fullName, $shortcut, InputOption::VALUE_NONE, $description); } else { $task->addOption($fullName, $shortcut, InputOption::VALUE_OPTIONAL, $description, $val); } } return $task; }
/** * 构造函数,处理配置 */ public function __construct() { $params = spExt('spUrlRewrite'); if (is_array($params)) { $this->params = array_merge($this->params, $params); } }
public function getField() { if (is_array($this->field)) { return $this->field[0]; } return $this->field; }
public function testFetchRates() { $currencyFromList = ['USD']; $currencyToList = ['EUR', 'UAH']; $responseBody = '{"base":"USD","date":"2015-10-07","rates":{"EUR":0.9022}}'; $expectedCurrencyRateList = ['USD' => ['EUR' => 0.9022, 'UAH' => null]]; $message = "We can't retrieve a rate from http://api.fixer.io/latest?base=USD&symbols=EUR,UAH for UAH."; /** @var \Magento\Directory\Model\Currency|\PHPUnit_Framework_MockObject_MockObject $currencyMock */ $currencyMock = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->disableOriginalConstructor()->setMethods([])->getMock(); /** @var \Magento\Framework\HTTP\ZendClient|\PHPUnit_Framework_MockObject_MockObject $currencyMock */ $httpClientMock = $this->getMockBuilder('Magento\\Framework\\HTTP\\ZendClient')->disableOriginalConstructor()->setMethods([])->getMock(); /** @var \Zend_Http_Response|\PHPUnit_Framework_MockObject_MockObject $currencyMock */ $httpResponseMock = $this->getMockBuilder('Zend_Http_Response')->disableOriginalConstructor()->setMethods([])->getMock(); $this->currencyFactoryMock->expects($this->any())->method('create')->willReturn($currencyMock); $currencyMock->expects($this->once())->method('getConfigBaseCurrencies')->willReturn($currencyFromList); $currencyMock->expects($this->once())->method('getConfigAllowCurrencies')->willReturn($currencyToList); $this->httpClientFactoryMock->expects($this->any())->method('create')->willReturn($httpClientMock); $httpClientMock->expects($this->atLeastOnce())->method('setUri')->willReturnSelf(); $httpClientMock->expects($this->atLeastOnce())->method('setConfig')->willReturnSelf(); $httpClientMock->expects($this->atLeastOnce())->method('request')->willReturn($httpResponseMock); $httpResponseMock->expects($this->any())->method('getBody')->willReturn($responseBody); $this->assertEquals($expectedCurrencyRateList, $this->model->fetchRates()); $messages = $this->model->getMessages(); $this->assertNotEmpty($messages); $this->assertTrue(is_array($messages)); $this->assertEquals($message, (string) $messages[0]); }
public function prepare_remote_upgrade($remoteMPID = 0) { $tp = new TaskPermission(); if ($tp->canInstallPackages()) { $mri = MarketplaceRemoteItem::getByID($remoteMPID); if (!is_object($mri)) { $this->set('error', array(t('Invalid marketplace item ID.'))); return; } $local = Package::getbyHandle($mri->getHandle()); if (!is_object($local) || $local->isPackageInstalled() == false) { $this->set('error', array(Package::E_PACKAGE_NOT_FOUND)); return; } $r = $mri->downloadUpdate(); if ($r != false) { if (!is_array($r)) { $this->set('error', array($r)); } else { $errors = Package::mapError($r); $this->set('error', $errors); } } else { $this->redirect('/dashboard/extend/update', 'do_update', $mri->getHandle()); } } }