public function addCommandsFromClass($className, $passThrough = null) { $roboTasks = new $className(); $commandNames = array_filter(get_class_methods($className), function ($m) { return !in_array($m, ['__construct']); }); foreach ($commandNames as $commandName) { $command = $this->createCommand(new TaskInfo($className, $commandName)); $command->setCode(function (InputInterface $input) use($roboTasks, $commandName, $passThrough) { // get passthru args $args = $input->getArguments(); array_shift($args); if ($passThrough) { $args[key(array_slice($args, -1, 1, TRUE))] = $passThrough; } $args[] = $input->getOptions(); $res = call_user_func_array([$roboTasks, $commandName], $args); if (is_int($res)) { exit($res); } if (is_bool($res)) { exit($res ? 0 : 1); } if ($res instanceof Result) { exit($res->getExitCode()); } }); $this->add($command); } }
function system_add_credentials() { if (!isset($_POST['AddCredentials'])) { $details = new stdClass(); $details->system_id = intval($this->uri->segment(3, 0)); if (!is_int($details->system_id) or $details->system_id == 0) { redirect('main/list_devices'); } $this->load->model("m_system"); $this->data['system_id'] = $details->system_id; $this->data['ip_address'] = ip_address_from_db($this->m_system->check_man_ip_address($details->system_id)); $this->data['heading'] = 'Add Device SNMP Credentials'; $this->data['include'] = 'v_add_system_c'; $this->load->view('v_template', $this->data); } else { $system_id = $_POST['system_id']; $this->load->model("m_system"); $this->load->library('encrypt'); if ($_POST['snmp_community'] > '' and $_POST['snmp_version'] > '' and $_POST['ip_address'] > '') { $encode['ip_address'] = $_POST['ip_address']; $encode['snmp_version'] = $_POST['snmp_version']; $encode['snmp_community'] = $_POST['snmp_community']; $encoded = json_encode($encode); $encoded = $this->encrypt->encode($encoded); $this->m_system->update_system_man($system_id, 'access_details', $encoded); if ($_POST['snmp_scan'] == TRUE) { redirect('admin_system/system_snmp/' . $system_id); } else { redirect('main/system_display/' . $system_id); } } else { redirect('admin_system/system_add_credentials/' . $system_id); } } }
public function setSelected($value = 'yes') { if (is_string($value) && ($value == 'yes' || $value == 'selected' || $value == 'on') || is_int($value) && $value != 0) { return $this->attributes['selected'] = 'selected'; } $this->removeAttribute('selected'); }
public function index() { $this->load_language('product/manufacturer'); $this->load->model('catalog/manufacturer'); $this->load->model('tool/image'); $this->document->setTitle($this->language->get('heading_title')); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_brand'), 'href' => $this->url->link('product/manufacturer'), 'separator' => $this->language->get('text_separator')); $this->data['categories'] = array(); $results = $this->model_catalog_manufacturer->getManufacturers(); foreach ($results as $result) { if (is_int(substr($result['name'], 0, 1))) { $key = '0 - 9'; } else { $key = substr(strtoupper($this->getFirstLetter($result['name'])), 0, 1); } if (!isset($this->data['manufacturers'][$key])) { $this->data['categories'][$key]['name'] = $key; } $this->data['categories'][$key]['manufacturer'][] = array('name' => $result['name'], 'href' => $this->url->link('product/manufacturer/product', 'manufacturer_id=' . $result['manufacturer_id'])); } sort($this->data['categories']); $this->data['continue'] = $this->url->link('common/home'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/manufacturer_list.tpl')) { $this->template = $this->config->get('config_template') . '/template/product/manufacturer_list.tpl'; } else { $this->template = 'default/template/product/manufacturer_list.tpl'; } $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $this->response->setOutput($this->render()); }
/** * @param KalturaMetadataFilter $filter * @param $shouldUpdate * @return int */ protected function indexMetadataObjects(KalturaMetadataFilter $filter, $shouldUpdate) { $filter->orderBy = KalturaMetadataOrderBy::CREATED_AT_ASC; $metadataPlugin = KalturaMetadataClientPlugin::get(KBatchBase::$kClient); $metadataList = $metadataPlugin->metadata->listAction($filter, $this->pager); if (!count($metadataList->objects)) { return 0; } KBatchBase::$kClient->startMultiRequest(); foreach ($metadataList->objects as $metadata) { $metadataPlugin->metadata->index($metadata->id, $shouldUpdate); } $results = KBatchBase::$kClient->doMultiRequest(); foreach ($results as $index => $result) { if (!is_int($result)) { unset($results[$index]); } } if (!count($results)) { return 0; } $lastIndexId = end($results); $this->setLastIndexId($lastIndexId); return count($results); }
public function detach(odObserver $observer) { if (is_int($key = array_search($observer, $this->__observers, true))) { unset($this->__observers[$key]); } return $this; }
public function setTimeout($seconds) { if (is_int($seconds)) { $this->timeout = $seconds; return true; } }
/** * Returns `true` if value is of the specified type * * @param string $type * @param mixed $value * @return bool */ protected function checkType($type, $value) { switch ($type) { case 'array': return is_array($value); case 'bool': case 'boolean': return is_bool($value); case 'callable': return is_callable($value); case 'float': case 'double': return is_float($value); case 'int': case 'integer': return is_int($value); case 'null': return is_null($value); case 'numeric': return is_numeric($value); case 'object': return is_object($value); case 'resource': return is_resource($value); case 'scalar': return is_scalar($value); case 'string': return is_string($value); case 'mixed': return true; default: return $value instanceof $type; } }
private function assertInteger($integer, $throwable = null) { $throwable = ThrowableUtilities::validateAndNormalizeThrowable($throwable, new Exception\InvalidArgumentException('Argument must be an integer')); if (!is_int($integer)) { throw $throwable; } }
/** * Generates, encodes, re-orders variables for the query string. * * @param array $params The specific parameters for this payment * @param array $pairs Pairs * @param string $namespace The namespace * * @return string An encoded string of parameters */ public static function generate_query_string($params, &$pairs = array(), $namespace = null) { if (is_array($params)) { foreach ($params as $k => $v) { if (is_int($k)) { GoCardless_Utils::generate_query_string($v, $pairs, $namespace . '[]'); } else { GoCardless_Utils::generate_query_string($v, $pairs, $namespace !== null ? $namespace . "[{$k}]" : $k); } } if ($namespace !== null) { return $pairs; } if (empty($pairs)) { return ''; } usort($pairs, array(__CLASS__, 'sortPairs')); $strs = array(); foreach ($pairs as $pair) { $strs[] = $pair[0] . '=' . $pair[1]; } return implode('&', $strs); } else { $pairs[] = array(rawurlencode($namespace), rawurlencode($params)); } }
public function setNbrPlanches($nbrPlanches) { $nbrPlanches = (int) $nbrPlanches; if (is_int($nbrPlanches) && $nbrPlanches >= 0) { $this->_nbrPlanches = $nbrPlanches; } }
public static function add($class, $behaviors) { foreach ($behaviors as $name => $parameters) { if (is_int($name)) { // no parameters $name = $parameters; } else { // register parameters foreach ($parameters as $key => $value) { sfConfig::set('propel_behavior_' . $name . '_' . $class . '_' . $key, $value); } } if (!isset(self::$behaviors[$name])) { throw new sfConfigurationException(sprintf('Propel behavior "%s" is not registered', $name)); } // register hooks foreach (self::$behaviors[$name]['hooks'] as $hook => $callables) { foreach ($callables as $callable) { sfMixer::register('Base' . $class . $hook, $callable); } } // register new methods foreach (self::$behaviors[$name]['methods'] as $callable) { sfMixer::register('Base' . $class, $callable); } } }
function mf_validate_float($value) { global $mf_lang; $error_message = $mf_lang['val_float']; $value = $value[0]; if (is_int($value)) { return $error_message; //it's integer } else { if (is_float($value)) { return true; //it's float } else { if (is_numeric($value)) { $result = strpos($value, '.'); if ($result !== false) { return true; //it's float } else { return $error_message; //it's integer } } else { return $error_message; //it's not even a number! } } } }
function savedata() { global $filesystem; $top = '<?php' . "\nif (defined('VISCACHA_CORE') == false) { die('Error: Hacking Attempt'); }\n"; $top .= '$' . $this->varname . ' = array();' . "\n"; $cfg = array(); while (list($key, $val) = each($this->data)) { if (is_array($val)) { foreach ($val as $key2 => $val2) { if (isset($this->opt[$key][$key2]) && $this->opt[$key][$key2] == int || is_int($val2)) { $val2 = intval($val2); } else { $val2 = $this->_prepareString($val2); } $cfg[] = '$' . $this->varname . "['{$key}']['{$key2}'] = {$val2};"; } } else { if (isset($this->opt[$key]) && $this->opt[$key] == int || is_int($val)) { $val = intval($val); } else { $val = $this->_prepareString($val); } $cfg[] = '$' . $this->varname . "['{$key}'] = {$val};"; } } natcasesort($cfg); $newdata = implode("\n", $cfg); $bottom = "\n" . '?>'; $filesystem->file_put_contents($this->file, $top . $newdata . $bottom); }
/** * Send data to realplexor. * Throw Dklab_Realplexor_Exception in case of error. * * @param mixed $idsAndCursors Target IDs in form of: array(id1 => cursor1, id2 => cursor2, ...) * of array(id1, id2, id3, ...). If sending to a single ID, * you may pass it as a plain string, not array. * @param mixed $data Data to be sent (any format, e.g. nested arrays are OK). * @param array $showOnlyForIds Send this message to only those who also listen any of these IDs. * This parameter may be used to limit the visibility to a closed * number of cliens: give each client an unique ID and enumerate * client IDs in $showOnlyForIds to not to send messages to others. * @return void */ public function send($idsAndCursors, $data, $showOnlyForIds = null) { $data = json_encode($data); $pairs = array(); foreach ((array) $idsAndCursors as $id => $cursor) { if (is_int($id)) { $id = $cursor; // this is NOT cursor, but ID! $cursor = null; } if (!preg_match('/^\\w+$/', $id)) { throw new Dklab_Realplexor_Exception("Identifier must be alphanumeric, \"{$id}\" given"); } $id = $this->_namespace . $id; if ($cursor !== null) { if (!is_numeric($cursor)) { throw new Dklab_Realplexor_Exception("Cursor must be numeric, \"{$cursor}\" given"); } $pairs[] = "{$cursor}:{$id}"; } else { $pairs[] = $id; } } if (is_array($showOnlyForIds)) { foreach ($showOnlyForIds as $id) { $pairs[] = "*" . $this->_namespace . $id; } } $this->_send(join(",", $pairs), $data); }
/** * @param string $ip IP of the MC server * @param int $port Port of the MC server * @param int $timeout Timeout * @throws InvalidArgumentException */ public function __construct($ip, $port = 25565, $timeout = 5) { $time = microtime(true); if (!is_int($timeout) || $timeout < 0) { throw new InvalidArgumentException('Timeout must be an integer.'); } // Connect to the server $this->socket = @fsockopen('udp://' . $ip, (int) $port, $errorNumber, $errorString, $timeout); // Failure? if ($errorNumber || $this->socket === false) { $this->online = false; return; } stream_set_blocking($this->socket, true); stream_set_timeout($this->socket, (int) $timeout); try { $challenge = $this->fetchChallenge(); $this->fetchStatus($challenge); } catch (MinecraftQueryException $e) { fclose($this->socket); $this->online = false; return; } fclose($this->socket); $this->duration = microtime(true) - $time; }
function submit() { //Check required Fields $missing = false; if (!isset($_POST["sql"]) || strlen($_POST["sql"]) == 0) { $missing = true; } if ($missing) { $this->res->success = false; $this->res->message = "missing required field!"; return null; } //get vars $sql = $_POST["sql"]; $schema_id = $this->params['schema_id']; $schema = Doo::db()->getOne('Schemata', array('where' => 'id = ' . $schema_id)); $async = isset($_POST['async']) ? $_POST['async'] : 0; $coord_name = isset($_POST['coord_name']) ? $_POST['coord_name'] : null; $query_id = isset($_POST["query_id"]) ? $_POST["query_id"] : strtoupper(md5(uniqid(rand(), true))); //init $shard_query = new ShardQuery($schema->schema_name); //error! if (!empty($shard_query->errors)) { //return $this->res->message = $shard_query->errors; $this->res->success = false; return null; } //set async $shard_query->async = $async == true ? true : false; //set coord shard if (isset($coord_name)) { $shard_query->set_coordinator($coord_name); } //execute query $stmt = $shard_query->query($sql); //error! if (!$stmt && !empty($shard_query->errors)) { //return $this->res->message = $shard_query->errors; $this->res->success = false; return null; } //empty results if ($stmt == null && empty($shard_query->errors)) { $this->res->data = array(); } //build data if (!is_int($stmt)) { $this->res->data = $this->json_format($shard_query, $stmt); $shard_query->DAL->my_free_result($stmt); } else { //save job_id $this->res->data = $stmt; } //save message $this->res->message = $query_id; //return $this->res->success = true; }
/** * @brief Définit la position du pointeur interne de l'itérateur * @return void */ protected function setPointeur($pointeur) { if (!is_int($pointeur)) { throw new IllegalArgumentException(); } $this->_pointeur = $pointeur; }
public function __construct(array $extent, array $size, array $wms = array()) { if (!is_array($extent) || count($extent) != 4) { throw new Exception('Extent must be an array of bottom, left, top, right coordinates'); } if (!is_array($size) || count($size) != 2) { throw new Exception('Size must be an array of width, height in pixel'); } foreach ($extent as $val) { if (!is_numeric($val)) { throw new Exception('An extent coordinate is not numeric ' . $val); } } foreach ($size as $val) { if (!is_int($val)) { throw new Exception('A size value is not an integer'); } } $this->extent = $extent; $this->size = $size; if (is_array($wms)) { if (count($wms) > 0) { try { foreach ($wms as $val) { $this->registerWMS($val); } } catch (Exception $e) { throw $e; } } } else { throw new Exception('wms parameter must be an array of WMS urls'); } }
public function reply($user, $message) { $message = $this->prepareMessage($message); $this->storeInput($message); $triggers = $this->tree['topics'][$this->getMetadata('topic')]['triggers']; if (count($triggers) > 0) { foreach ($triggers as $key => $trigger) { foreach ($this->triggers as $class) { $triggerClass = "\\Vulcan\\Rivescript\\Triggers\\{$class}"; $triggerClass = new $triggerClass(); $found = $triggerClass->parse($key, $trigger['trigger'], $message); if (isset($found['match']) and $found['match'] === true) { log_debug('Found match', ['type' => $class, 'message' => $message, 'found' => $found]); break 2; } } } if (isset($found['key']) and is_int($found['key'])) { $replies = $triggers[$found['key']]['reply']; if (isset($triggers[$found['key']]['redirect'])) { return $this->reply($user, $triggers[$found['key']]['redirect']); } if (count($replies)) { $key = array_rand($replies); $reply = $this->parseReply($replies[$key], $found['data']); return $reply; } } } return 'No response found.'; }
/** * @param InputInterface $input * @param OutputInterface $output * @param array $items * @param string $prefix */ protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { switch ($input->getOption('output')) { case self::OUTPUT_FORMAT_JSON: $output->writeln(json_encode($items)); break; case self::OUTPUT_FORMAT_JSON_PRETTY: $output->writeln(json_encode($items, JSON_PRETTY_PRINT)); break; default: foreach ($items as $key => $item) { if (is_array($item)) { $output->writeln($prefix . $key . ':'); $this->writeArrayInOutputFormat($input, $output, $item, ' ' . $prefix); continue; } if (!is_int($key)) { $value = $this->valueToString($item); if (!is_null($value)) { $output->writeln($prefix . $key . ': ' . $value); } else { $output->writeln($prefix . $key); } } else { $output->writeln($prefix . $this->valueToString($item)); } } break; } }
function testCorrect() { $xml = '<?xml version="1.0"?> <d:principal-search-property-set xmlns:d="DAV:"/>'; $serverVars = array('REQUEST_METHOD' => 'REPORT', 'HTTP_DEPTH' => '0', 'REQUEST_URI' => '/principals'); $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); $server->httpRequest = $request; $server->exec(); $this->assertEquals(200, $server->httpResponse->status, $server->httpResponse->body); $this->assertEquals(array('X-Sabre-Version' => [DAV\Version::VERSION], 'Content-Type' => ['application/xml; charset=utf-8']), $server->httpResponse->getHeaders()); $check = array('/d:principal-search-property-set', '/d:principal-search-property-set/d:principal-search-property' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname' => 1, '/d:principal-search-property-set/d:principal-search-property/d:prop/s:email-address' => 1, '/d:principal-search-property-set/d:principal-search-property/d:description' => 2); $xml = simplexml_load_string($server->httpResponse->body); $xml->registerXPathNamespace('d', 'DAV:'); $xml->registerXPathNamespace('s', 'http://sabredav.org/ns'); foreach ($check as $v1 => $v2) { $xpath = is_int($v1) ? $v2 : $v1; $result = $xml->xpath($xpath); $count = 1; if (!is_int($v1)) { $count = $v2; } $this->assertEquals($count, count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body); } }
/** * Builds the regex and censor cache value for a find/replace pair * * @param string $find * @param string $replace * * @return array|bool */ public static function buildCensorCacheValue($find, $replace) { $find = trim(strval($find)); if ($find === '') { return false; } $prefixWildCard = preg_match('#^\\*#', $find); $suffixWildCard = preg_match('#\\*$#', $find); $replace = is_int($replace) ? '' : trim(strval($replace)); if ($replace === '') { $replace = utf8_strlen($find); if ($prefixWildCard) { $replace--; } if ($suffixWildCard) { $replace--; } } $regexFind = $find; if ($prefixWildCard) { $regexFind = substr($regexFind, 1); } if ($suffixWildCard) { $regexFind = substr($regexFind, 0, -1); } if (!strlen($regexFind)) { return false; } $regex = '#' . ($prefixWildCard ? '' : '(?<=\\W|^)') . preg_quote($regexFind, '#') . ($suffixWildCard ? '' : '(?=\\W|$)') . '#iu'; return array('word' => $find, 'regex' => $regex, 'replace' => $replace); }
/** * 设置 HTTP 状态代码 * * @param int $status */ public function setStatus($status) { if (!is_int($status) || !static::getMessageForCode($status)) { throw new \Exception('Invalid HTTP status code'); } $this->status = (int) $status; }
/** * Sets number of seconds between each RSS fetch. * * @param int $interval Number of seconds. * * @throws \InvalidArgumentException Thrown if interval is smaller than 1 or not integer. */ public function setInterval($interval) { if (!is_int($interval) || $interval < 1) { throw new \InvalidArgumentException('Specified interval value cannot be used - it should be integer not smaller than 1'); } $this->interval = $interval; }
/** * @param array $values * @return PPNode_DOM * @throws MWException */ public function newPartNodeArray($values) { // NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais) $xml = "<list>"; foreach ($values as $k => $val) { if (is_int($k)) { $xml .= "<part><name index=\"{$k}\"/><value>" . htmlspecialchars($val) . "</value></part>"; } else { $xml .= "<part><name>" . htmlspecialchars($k) . "</name>=<value>" . htmlspecialchars($val) . "</value></part>"; } } $xml .= "</list>"; $dom = new DOMDocument(); MediaWiki\suppressWarnings(); $result = $dom->loadXML($xml); MediaWiki\restoreWarnings(); if (!$result) { // Try running the XML through UtfNormal to get rid of invalid characters $xml = UtfNormal\Validator::cleanUp($xml); // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 // don't barf when the XML is >256 levels deep $result = $dom->loadXML($xml, 1 << 19); } if (!$result) { throw new MWException('Parameters passed to ' . __METHOD__ . ' result in invalid XML'); } $root = $dom->documentElement; $node = new PPNode_DOM($root->childNodes); return $node; }
/** * Set bitfield composite value. * If value string starts with '0x', then decode it as hex * * @param string|int $value */ public function setValue($value) { if (substr($value, 0, 2) == '0x') { $value = $this->hex2dec($value); } // see if value is small enough to use bitwise ops if (is_int($value)) { $useBitOps = true; } else { $useBitOps = false; } $this->realValue = $value; foreach ($this->structure as $key => $bits) { if ($value == 0) { $val = 0; } elseif ($useBitOps) { // we need value for first N bits $mask = (1 << $bits) - 1; $val = $value & $mask; // remove processed bits from value // shifted highest bits are not cleared // and might remain as 1 $value = $value >> $bits; } else { // we need value for first N bits $pow = bcpow(2, $bits); $val = bcmod($value, $pow); // remove processed bits from value $value = bcdiv($value, $pow); } $this->values[$key] = $val; } }
/** * Compiles code for the execution of block plugin * * @param array $args array with attributes from parser * @param string $tag name of block function * @param string $methode name of methode to call * @param object $compiler compiler object * @return string compiled code */ public function compile($args, $compiler, $tag, $methode) { $this->compiler = $compiler; if (strlen($tag) < 5 || substr_compare($tag, 'close', -5, 5) != 0) { // opening tag of block plugin $this->required_attributes = array(); $this->optional_attributes = array('_any'); // check and get attributes $_attr = $this->_get_attributes($args); // convert attributes into parameter array string $_paramsArray = array(); foreach ($_attr as $_key => $_value) { if (is_int($_key)) { $_paramsArray[] = "{$_key}=>{$_value}"; } else { $_paramsArray[] = "'{$_key}'=>{$_value}"; } } $_params = 'array(' . implode(",", $_paramsArray) . ')'; $this->_open_tag($tag . '->' . $methode, $_params); // compile code $output = '<?php $_block_repeat=true; $_smarty_tpl->smarty->registered_objects[\'' . $tag . '\'][0]->' . $methode . '(' . $_params . ', null, $_smarty_tpl->smarty, $_block_repeat, $_smarty_tpl);while ($_block_repeat) { ob_start();?>'; } else { // closing tag of block plugin $_params = $this->_close_tag(substr($tag, 0, -5) . '->' . $methode); // This tag does create output $this->compiler->has_output = true; // compile code $output = '<?php $_block_content = ob_get_contents(); ob_end_clean(); $_block_repeat=false; echo $_smarty_tpl->smarty->registered_objects[\'' . substr($tag, 0, -5) . '\'][0]->' . $methode . '(' . $_params . ', $_block_content, $_smarty_tpl->smarty, $_block_repeat, $_smarty_tpl); }?>'; } return $output; }
public static function formatMessage(Rule $rule, $withValue = TRUE) { $message = $rule->message; if ($message instanceof Nette\Utils\Html) { return $message; } elseif ($message === NULL && is_string($rule->validator) && isset(static::$messages[$rule->validator])) { $message = static::$messages[$rule->validator]; } elseif ($message == NULL) { // intentionally == trigger_error("Missing validation message for control '{$rule->control->getName()}'.", E_USER_WARNING); } if ($translator = $rule->control->getForm()->getTranslator()) { $message = $translator->translate($message, is_int($rule->arg) ? $rule->arg : NULL); } $message = preg_replace_callback('#%(name|label|value|\\d+\\$[ds]|[ds])#', function ($m) use($rule, $withValue) { static $i = -1; switch ($m[1]) { case 'name': return $rule->control->getName(); case 'label': return $rule->control->translate($rule->control->caption); case 'value': return $withValue ? $rule->control->getValue() : $m[0]; default: $args = is_array($rule->arg) ? $rule->arg : array($rule->arg); $i = (int) $m[1] ? $m[1] - 1 : $i + 1; return isset($args[$i]) ? $args[$i] instanceof IControl ? $withValue ? $args[$i]->getValue() : "%{$i}" : $args[$i] : ''; } }, $message); return $message; }
public function addOptions(array $options) { foreach ($options as $key => $option) { if (is_object($option)) { if (!$option instanceof Option) { throw new Exception('An option is not valid for option factory. It should be an instance of Option, ' . 'instead an instance of ' . get_class($option) . ' was given'); } } elseif (is_array($option)) { if (!is_string($key)) { throw new Exception('An option is not valid for option factory.When the value is an array ' . 'then the key should be a string that represents the name of the optgroup'); } else { $option = new OptGroup($key, $option); } } else { if (!is_string($option)) { throw new Exception('An option is not valid for option factory. It should be a string, ' . 'instead ' . gettype($option) . ' was given'); } if (is_int($key)) { $option = new Option($option, $option); } elseif (is_string($key)) { $option = new Option($option, $key); } } $this->addOption($option); } }