protected function update($data = array(), $params = array(), $otherTables = false) { $tables = ""; if (!empty($otherTables)) { foreach ($otherTables as $table) { $tables .= "," . $table . " "; } } $values = ''; foreach ($data as $field => $value) { if (getType($value) == 'integer') { $values .= $field . "=" . addslashes($value) . ","; } else { $values .= $field . "='" . addslashes($value) . "',"; } } $condition = !empty($params['condition']) ? $params['condition'] : '1=1'; $sql = "UPDATE " . $this->table . $tables . " SET " . substr($values, 0, -1) . " WHERE " . $condition; //echo "<meta charset='UTF-8'>UPDATE ".$this->table.$tables." SET ".substr($values,0,-1)." WHERE ".$condition.'<br>'.'<br>'; try { $request = self::$connexion->prepare($sql); $request->execute(); } catch (Exception $error) { die('FAILED UPDATE : ' . $error->getMessage()); } }
public function saveFile($url, $file, $name) { $file_type = getType($file); if ($file_type != '') { copy($file['tmp_name'], $url . $name . '.' . $file_type); } }
/** * CreateResponse - Response handler to handle API Requests * * @param int $apiStatusCode The HTTP Status Code * * @return ApiResponse */ public static function CreateResponse($apiStatusCode, $requestResult = []) { if (getType($requestResult) == "array") { $requestResult = json_encode($requestResult); } $request_result = json_decode($requestResult, true); $request_result["records"] = array_key_exists("data", $request_result) ? count($request_result["data"]) : count($request_result); $statusType = ApiResponse::$statusMessages[$apiStatusCode]["status_type"]; $successStatus = $statusType == "success" ? true : false; $statusCode = ApiResponse::$statusMessages[$apiStatusCode]["status_code"]; $response = ["code" => $statusCode, "message" => Response::$statusTexts[$statusCode], "description" => ApiResponse::$statusCodeMessages[$statusCode], "reason" => ApiResponse::$statusMessages[$apiStatusCode]["status_text"], "apistatuscode" => $apiStatusCode]; $return = ["success" => $successStatus]; if ($statusType == "success") { $return["response"] = $response; } elseif ($statusType == "error") { $return["error"] = $response; } if (!empty($requestResult)) { $return["result"] = json_decode($requestResult, true); $return["date"] = date("Y-m-d"); $return["time"] = date("H:i:s"); } // Return Result return $return; }
/** * Map a PHP data type to ours * @param mixed $value Any type of data * @throws Exception */ public static function convert($type) { switch (getType($type)) { case 'NULL': return Type::NULL; break; case 'boolean': return Type::BOOLEAN; break; case 'integer': return Type::INTEGER; break; case 'double': return Type::FLOAT; break; case 'string': return Type::STRING; break; case 'array': return Type::COLLECTION; break; case 'object': return Type::OBJECT; break; case 'resource': return Type::RESOURCE; break; case 'unknown type': return Type::UNKNOWN; break; } }
function HTMLTemplate($name, $replace, $with) { $loc = $this->templateKey[$name]; $webRoot = getWebRoot(); if (getType($replace) == getType($with) && getType($replace) == "array" && count($replace) > 0) { if (count($replace) == count($with)) { array_unshift($replace, "{webRoot}"); array_unshift($with, $webRoot); } else { echo "error: Replace and With arrays are of different lengths."; } } else { $replace = array('{webRoot}'); $with = array($webRoot); } if (isset($loc)) { $html = file_get_contents($loc); if ($html) { if ($replace && $with) { $htmlWithVars = str_replace($replace, $with, $html); } else { $htmlWithVars = $html; } echo $htmlWithVars; } } else { // echo header("Location:error.php?num=2"); echo "error: Missing HTML template of {$name}"; } }
/** * Sets the name of the config-entry. * @param string $strConfig the name of the config-entry. * @return Dkplus_Controller_Plugin_Database * @throws Zend_Controller_Exception on wrong parameter. */ public function setConfigParameter($strConfig) { if (!is_string($strConfig)) { throw new Zend_Controller_Exception('$strConfig is an ' . getType($strConfig) . ', must be an string'); } $this->_configName = $strConfig; }
/** * 入力チェック処理 * @param array $data 入力データ * @param array &$valid_data 入力チェック後の返却データ * @param array $white_list 入力のチェック許可リスト */ public function validate($data, &$valid_data, $white_list = array()) { $errors = array(); $valid_data = array(); $isWhiteList = !!count($white_list); foreach ($this->validates as $key => $valid) { // カラムのホワイトリストチェック if ($isWhiteList && !in_array($key, $white_list)) { continue; } foreach ($valid as $mKey => $options) { $method = is_array($options) && isset($options['rule']) ? $options['rule'] : $mKey; if (!isset($data[$key])) { $data[$key] = null; } $error = Validate::$method($data[$key], $options, $key, $data, $this); if ($error === false) { break; } if (getType($error) === 'string') { $errors[$key] = $error; break; } } if (isset($data[$key])) { $valid_data[$key] = $data[$key]; } } return $errors; }
protected function serializeArrayToXml(array $array, DOMElement $element) { foreach ($array as $name => $value) { $property = $element->appendChild($element->ownerDocument->createElement('property')); $property->setAttribute('key-type', is_string($name) ? 'string' : 'integer'); $property->setAttribute('key-name', $name); switch ($type = gettype($value)) { case 'double': $type = 'float'; case 'integer': // $type has already been set $property->appendChild($element->ownerDocument->createTextNode((string) $value)); break; case 'boolean': // $type has already been set $property->appendChild($element->ownerDocument->createTextNode($value ? '1' : '0')); break; case 'string': $property->appendChild($element->ownerDocument->createCDATASection($value)); break; case 'array': // $type has been set // recursively serialize the array $this->serializeArrayToXml($value, $property); break; default: //@todo throw new Exception('Can not serialize type ' . getType($value) . ' in configuration setting ' . $name); } $property->setAttribute('value-type', $type); } }
/** * Just set member variables and check the values are correct * * @param int $code The response code * @param array of string $message The response message * @return void */ public function __construct($code, array $message) { if (!is_numeric($code)) { throw new InvalidArgumentException('SMTP response code must be a ' . 'number, but (' . getType($code) . ')' . $code . ' given.'); } $this->code = $code; $this->message = $message; }
public static function typeName($arg) { $t = getType($arg); if ($t == "object") { return get_class($arg); } return $t; }
/** * Schedule generator constructor. Creates schedule sequence for selected objects * * @param array|Traversable $objects */ public function __construct($objects = []) { if (!is_array($objects) && !$objects instanceof \Traversable) { throw new \InvalidArgumentException(sprintf("Expects an array or Traversable object, '%s' has given", getType($object))); } foreach ($objects as $object) { $this->add($object); } }
public static function toObject($arr) {/*{{{*/ if(gettype($arr) != 'array') return $arr; foreach ($arr as $k=>$v) { if(gettype($v) == 'array' || getType($v) == 'object') $arr[$k] = (object) self::toObject($v); } return (object) $arr; }/*}}}*/
function getBrokenThemeSettings($id) { $themeSettings = WikiFactory::getVarByName('wgOasisThemeSettings', $id); if (!is_object($themeSettings) || empty($themeSettings->cv_value)) { return null; } $themeSettingsArray = unserialize($themeSettings->cv_value); $backgroundImage = $themeSettingsArray['background-image']; return getType($backgroundImage) !== 'string' || $backgroundImage === 'false' ? $themeSettingsArray : null; }
protected function debug($arrayToDebug = array(), $array_name = false) { $title = !empty($array_name) ? $array_name : ""; if (getType($arrayToDebug) == "array") { ksort($arrayToDebug); } echo "<meta charset='UTF-8'>\n <h1 style='margin-bottom:-35px!important;position:relative;z-index:9999!important;'>" . $title . "</h1>\n <pre style='margin:50px!important;background-color:#AEAEAE!important;border:solid 2px red!important;z-index:9999!important;position:relative;'>"; print_r($arrayToDebug); echo "</pre><br>"; }
/** * @param array|ModelInterface $dataOrModel * @param HydratorInterface $hydrator * @return array */ public function extract($dataOrModel, HydratorInterface $hydrator = null) { if (is_array($dataOrModel)) { return $dataOrModel; } if (!$dataOrModel instanceof ModelInterface) { throw new \InvalidArgumentException('Model object needs to implement ModelInterface got: ' . getType($dataOrModel)); } $hydrator = $hydrator ?: $this->getHydrator(); return $hydrator->extract($dataOrModel); }
/** * Create a new scalar based on type of original matrix * * @param \Chippyash\Math\Matrix\NumericMatrix $originalMatrix * @param scalar $scalar * @return Chippyash\Type\Interfaces\NumericTypeInterface * */ protected function createCorrectScalarType(NumericMatrix $originalMatrix, $scalar) { if ($scalar instanceof NumericTypeInterface) { if ($originalMatrix instanceof RationalMatrix) { return $scalar->asRational(); } if ($originalMatrix instanceof ComplexMatrix) { return $scalar->asComplex(); } return $scalar; } if ($originalMatrix instanceof ComplexMatrix) { if (is_numeric($scalar)) { return ComplexTypeFactory::create($scalar, 0); } if (is_string($scalar)) { try { return RationalTypeFactory::create($scalar)->asComplex(); } catch (\Exception $e) { //do nothing } } if (is_bool($scalar)) { return ComplexTypeFactory::create($scalar ? 1 : 0, 0); } return ComplexTypeFactory::create($scalar); } if ($originalMatrix instanceof RationalMatrix) { if (is_bool($scalar)) { $scalar = $scalar ? 1 : 0; } return RationalTypeFactory::create($scalar); } //handling for NumericMatrix if (is_int($scalar)) { return TypeFactory::createInt($scalar); } elseif (is_float($scalar)) { return TypeFactory::createRational($scalar); } elseif (is_bool($scalar)) { return TypeFactory::createInt($scalar ? 1 : 0); } elseif (is_string($scalar)) { try { return TypeFactory::createRational($scalar); } catch (\InvalidArgumentException $e) { try { return ComplexTypeFactory::create($scalar); } catch (\InvalidArgumentException $e) { //do nothing } } } throw new ComputationException('Scalar parameter is not a supported type for numeric matrices: ' . getType($scalar)); }
public static function parse($e) { if (gettype($e) != 'array') { return; } foreach ($e as $k => $v) { if (gettype($v) == 'array' || getType($v) == 'object') { $e[$k] = self::parse($v); } } return (object) $e; }
function arrayToObject($e) { if (gettype($e) != 'array') { return; } foreach ($e as $k => $v) { if (gettype($v) == 'array' || getType($v) == 'object') { $e[$k] = (object) arrayToObject($v); } } return (object) $e; }
function serialiseArray($parent, $array, $tagName = null) { if (is_array($array)) { foreach ($array as $key => $val) { $attr = null; if (!is_int($key)) { $attr = array('name' => $key, 'type' => getType($val)); } $key = get_class($val) != null ? get_class($val) : is_int($key) ? gettype($val) : $key; $this->serialiseValue($parent, $val, $key, $attr); } } }
/** * Pass in a value and get the validated value back * * @param mixed $value * @return mixed * @throws ValidationException */ public function validateData($value) { if ($this->getType() != getType($value)) { if ($this->getRequired()) { throw new \ClassyLlama\AvaTax\Framework\Interaction\MetaData\ValidationException(__('The value you passed in is not an object.')); } $value = null; } $class = $this->getClass(); if (!is_null($value) && !$value instanceof $class) { throw new \ClassyLlama\AvaTax\Framework\Interaction\MetaData\ValidationException(__('The object you passed in is of type %1 and is required to be of type %2.', [get_class($value), $class])); } return $value; }
/** * {@inheritDoc} * * @return \Doctrine\Common\Cache\Cache * * @throws RuntimeException */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { /** @var $options \DoctrineModule\Options\Cache */ $options = $this->getOptions($container, 'cache'); $instance = $options->getInstance(); if (!$instance) { // @todo move this validation to the options class throw new RuntimeException('ZendStorageCache must have a referenced cache instance'); } $cache = $container->get($instance); if (!$cache instanceof StorageInterface) { throw new RuntimeException(sprintf('Retrieved storage "%s" is not a Zend\\Cache\\Storage\\StorageInterface instance, %s found', $instance, is_object($cache) ? get_class($cache) : getType($cache))); } return new ZendStorageCache($cache); }
/** * {@inheritDoc} * @return ZendStorageCache * @throws RuntimeException */ public function createService(ServiceLocatorInterface $sl) { /** @var $options \DoctrineModule\Options\Cache */ $options = $this->getOptions($sl, 'cache'); $instance = $options->getInstance(); if (!$instance) { // @todo move this validation to the options class throw new RuntimeException('ZendStorageCache must have a referenced cache instance'); } $cache = $sl->get($instance); if (!$cache instanceof StorageInterface) { throw new RuntimeException(sprintf('Retrieved storage "%s" is not a Zend\\Cache\\Storage\\StorageInterface instance, %s found', $instance, is_object($cache) ? get_class($cache) : getType($cache))); } return new ZendStorageCache($cache); }
public function testGetTotalTimeReturnsExpectedResults() { $typeName = 'user'; $index = $this->_createIndex(); $type = $index->getType($typeName); // Adds 1 document to the index $docId = 3; $doc1 = new Document($docId, array('username' => 'hans')); $type->addDocument($doc1); // Refreshes index $index->refresh(); $resultSet = $type->search('hans'); $this->assertNotNull($resultSet->getTotalTime(), 'Get Total Time should never be a null value'); $this->assertEquals('integer', getType($resultSet->getTotalTime()), 'Total Time should be an integer'); }
/** * @param array $options * @throws \Zend\Validator\Exception\InvalidArgumentException */ public function __construct(array $options) { if (!isset($options['exclude']) || !is_scalar($options['exclude'])) { if (!isset($options['exclude'])) { $provided = 'nothing'; } else { if (is_object($options['exclude'])) { $provided = get_class($options['exclude']); } else { $provided = getType($options['exclude']); } } throw new Exception\InvalidArgumentException(sprintf('Option "exclude" is required and must be the primary key' . ' value of the object to exclude, %s given', $provided)); } $this->exclude = $options['exclude']; parent::__construct($options); }
/** * @param array $options * @throws \Zend\Validator\Exception\InvalidArgumentException */ public function __construct(array $options) { parent::__construct($options); if (!isset($options['join']) || !is_scalar($options['join'])) { if (!isset($options['join'])) { $provided = 'nothing'; } else { if (is_object($options['join'])) { $provided = get_class($options['join']); } else { $provided = getType($options['join']); } } throw new Exception\InvalidArgumentException(sprintf('Option "join" is required and must be the field name' . ' of the association to join to, %s given', $provided)); } $this->join = $options['join']; }
/** * Test convertHexToRGB */ public function testConvertHexToRGB() { // First test $hex = 'ffffff'; $rgb = ImageWorkshopLib::convertHexToRGB($hex); $this->assertTrue(getType($rgb) === 'array', 'Expect $rgb to be an array'); $this->assertTrue((array_key_exists('R', $rgb) && array_key_exists('G', $rgb) && array_key_exists('B', $rgb)) == 3, 'Expect $rgb to have the 3 array keys: "R", "G", and "B"'); $this->assertTrue($rgb['R'] === 255, 'Expect $rgb["R"] to be an integer of value 255'); $this->assertTrue($rgb['G'] === 255, 'Expect $rgb["G"] to be an integer of value 255'); $this->assertTrue($rgb['B'] === 255, 'Expect $rgb["B"] to be an integer of value 255'); // Second test $hex = '000000'; $rgb = ImageWorkshopLib::convertHexToRGB($hex); $this->assertTrue($rgb['R'] === 0, 'Expect $rgb["R"] to be an integer of value 0'); $this->assertTrue($rgb['G'] === 0, 'Expect $rgb["G"] to be an integer of value 0'); $this->assertTrue($rgb['B'] === 0, 'Expect $rgb["B"] to be an integer of value 0'); }
/** * Constructor * * @param array $options required keys are `enum`, which must be an instance of * ZB\Utils\Enum\Enum * @throws \Zend\Validator\Exception\InvalidArgumentException */ public function __construct(array $options) { if (!isset($options['enum']) || !$options['enum'] instanceof EnumAbstract) { if (!array_key_exists('enum', $options)) { $provided = 'nothing'; } else { if (is_object($options['enum'])) { $provided = get_class($options['enum']); } else { $provided = getType($options['enum']); } } throw new Exception\InvalidArgumentException(sprintf('Option "enum" is required and must be an instance of ZB\\Utils\\Enum\\Enum, %s given', $provided)); } $this->enum = $options['enum']; parent::__construct($options); }
public function __construct(array $options) { parent::__construct($options); if (!isset($options['object_manager']) || !$options['object_manager'] instanceof ObjectManager) { if (!array_key_exists('object_manager', $options)) { $provided = 'nothing'; } else { if (is_object($options['object_manager'])) { $provided = get_class($options['object_manager']); } else { $provided = getType($options['object_manager']); } } throw new Exception\InvalidArgumentException(sprintf('Option "object_manager" is required and must be an instance of' . ' Doctrine\\Common\\Persistence\\ObjectManager, %s given', $provided)); } $this->objectManager = $options['object_manager']; }
public function testDefaultPageLoadInvocationFetchesOnlyTheFirstTenAutorespondersInOrderOfCreation() { $this->newsletterId = $this->newsletterId; $autorespondersRowList = AutoresponderTestHelper::addAutoresponderObjects($this->newsletterId, 20); $this->autoresponderController->autorespondersListPage(); $numberOfPagesInAutorespondersList = intval(_wpr_get("number_of_pages")); $autorespondersListToRender = _wpr_get("autoresponders"); $first10Autoresponders = array_slice($autorespondersRowList, 0, 10); $autoresponderNamesFromRows = self::getAutoresponderNamesFromRows($first10Autoresponders); $autoresponderNamesFromObjects = self::getAutoresponderNamesFromAutoresponderObjects($autorespondersListToRender); $difference = array_diff($autoresponderNamesFromRows, $autoresponderNamesFromObjects); $numberOfDifferingRows = count($difference); $viewToRender = _wpr_get("_wpr_view"); $this->assertEquals("integer", getType($numberOfPagesInAutorespondersList)); $this->assertEquals(2, $numberOfPagesInAutorespondersList); $this->assertEquals(0, $numberOfDifferingRows); $this->assertEquals("autoresponders_home", $viewToRender); }
/** * Pass in a value and get the validated value back * If your data can be converted to an array, please do so explicitly before passing in * because automated array conversion will not be attempted since it can have unexpected results. * * @param mixed $value * @return mixed * @throws LocalizedException */ public function validateData($value) { if ($this->getType() != getType($value)) { if ($this->getRequired()) { throw new \ClassyLlama\AvaTax\Framework\Interaction\MetaData\ValidationException(__('The value you passed in is not an array. ' . 'If your data can be converted to an array, please do so explicitly before passing it in ' . 'because automated array conversion will not be attempted since it can have unexpected results.')); } $value = []; } // If a subtype is defined, call this function for that contents of the array if (!is_null($this->getSubtype())) { $value = $this->getSubtype()->validateData($value); } // If the length exceeds the maximum allowed length, throw an exception if ($this->getLength() > 0 && count($value) > $this->getLength()) { throw new \ClassyLlama\AvaTax\Framework\Interaction\MetaData\ValidationException(__('You attempted to pass data to the AvaTax API with the key of %1,' . ' with a length of %2, the max allowed length is %3.', [$this->getName(), count($value), $this->getLength()])); } return $value; }