本文整理汇总了PHP中CPropertyValue::ensureArray方法的典型用法代码示例。如果您正苦于以下问题:PHP CPropertyValue::ensureArray方法的具体用法?PHP CPropertyValue::ensureArray怎么用?PHP CPropertyValue::ensureArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPropertyValue
的用法示例。
在下文中一共展示了CPropertyValue::ensureArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
public function send($phones, $text)
{
$request = new DOMDocument("1.0", "UTF-8");
$requestBody = $request->createElement('SMS');
$requestBody->appendChild($this->createOperationsElement(array(self::SEND)));
$requestBody->appendChild($this->createAuthElement());
$request->appendChild($requestBody);
$sms = $request->createElement('message');
$sms->appendChild($request->createElement('sender', $this->sender));
$textElement = $request->createElement('text');
$textElement->appendChild(new DOMCdataSection($text));
$sms->appendChild($textElement);
$requestBody->appendChild($sms);
if (is_array($phones) == false) {
$phones = array($phones => array());
}
$numbers = $request->createElement('numbers');
foreach ($phones as $phone => $value) {
$variables = implode(';', CPropertyValue::ensureArray($value)) . ';';
$number = $request->createElement('number', $phone);
$number->setAttribute('messageid', md5($phone . date() . $variables));
$number->setAttribute('variables', $variables);
$numbers->appendChild($number);
}
$requestBody->appendChild($numbers);
$responseText = $this->doRequest($request->saveXML());
$result = $this->parseResponse($responseText);
$status = $result['status'];
$ok = (bool) ($status > 0);
$needSmsAlert = $ok == false && $status != -4;
$credits = $this->balance();
return array('status' => $status, 'ok' => $ok, 'responseText' => $responseText, 'credits' => $credits, 'needSmsAlert' => $needSmsAlert);
}
示例2: testEnsureArray
public function testEnsureArray()
{
$entries = array(array(123, array(123)), array(null, array()), array('', array()), array('abc', array('abc')), array('(1,2)', array(1, 2)), array('("key"=>"value",2=>3)', array("key" => "value", 2 => 3)), array(true, array(true)), array(array(), array()), array(array(0), array(0)));
foreach ($entries as $index => $entry) {
$this->assertTrue(CPropertyValue::ensureArray($entry[0]) === $entry[1], "Comparison {$index}: {$this->varToString($entry[0])}=={$this->varToString($entry[1])}");
}
}
示例3: convertType
public function convertType($value)
{
$value = trim($value);
if (ctype_digit($value)) {
return CPropertyValue::ensureInteger($value);
}
if (is_numeric($value)) {
return CPropertyValue::ensureFloat($value);
}
if (strcasecmp($value, 'null') == 0) {
return null;
} else {
if (strcasecmp($value, 'true') == 0 || strcasecmp($value, 'false') == 0) {
return CPropertyValue::ensureBoolean($value);
} else {
if (preg_match('/^\\(.+\\)|\\(\\)$/', $value)) {
return CPropertyValue::ensureArray($value);
}
}
}
return $value;
}
示例4: send
public function send($phones, $text)
{
$sender = $this->sender;
$result = array();
foreach ($phones as $phone => $variables) {
$variables = CPropertyValue::ensureArray($variables);
$textMsg = $text;
$i = 1;
foreach ($variables as $variable) {
$textMsg = str_replace('%' . $i . '%', $variable, $textMsg);
$i++;
}
$args = array('login' => $this->username, 'password' => $this->password, 'messages' => array(array('clientId' => $sender, 'phone' => $phone, 'text' => $text)));
$response = $this->doRequest(self::SEND_URL, $args);
$responseText = CJSON::encode($response);
$resultStatus = false;
$credits = 0;
$status = isset($response['status']) ? $response['status'] : 'no status';
if ($status == 'ok') {
if (isset($response['messages']) == false || count($response['messages']) == 0) {
throw new Exception('No messages in response');
}
$message = $response['messages'][0];
$status = isset($message['status']) ? $message['status'] : 'no status';
$resultStatus = $status == 'accepted';
$response = $this->doRequest(self::CREDITS_URL, array('login' => $this->username, 'password' => $this->password));
if (isset($response['balance'])) {
$credits = $response['balance'][0]['balance'];
} else {
throw new Exception('No credits in response');
}
}
$result = array('ok' => $status == 'ok', 'status' => $status, 'responseText' => $responseText, 'credits' => $credits, 'needSmsAlert' => true);
}
return $result;
}
示例5: setScopes
public function setScopes ($scopes)
{
$this->_scopes = CPropertyValue::ensureArray($scopes);
}
示例6: applyFlags
/**
* Apply flags conditions to given criteria
* @param CDbCriteria $criteria the criteria to apply flags condition
* @param array $flags the array with flags (as flag name or as flag value). Flag name started with '!' is mean 'not flag'
* @param string $operator the operator that connect flags conditions
* @return CDbCriteria the CDbCriteria object with applied flags conditions
*/
public function applyFlags($criteria, $flags, $operator = 'AND')
{
$flagList = $this->cachedFlags();
$flags = CPropertyValue::ensureArray($flags);
$newCriteria = new CDbCriteria();
foreach ($flags as $flag) {
if (is_string($flag)) {
if ($invert = $flag[0] == '!') {
$flag = substr($flag, 1);
}
$flagValue = $flagList[trim(strtolower($flag))];
} else {
$flagValue = $flag;
}
if (empty($flagValue) === false) {
$equality = $invert ? '=' : '<>';
$newCriteria->addCondition($this->flagsField . '&' . $flagValue . $equality . '0', $operator);
}
}
$criteria->mergeWith($newCriteria);
return $criteria;
}
示例7: prepareOutput
private function prepareOutput()
{
$preparedAttributes = array();
foreach ($this->getAttributes() as $key => $value) {
if (in_array($key, array('enableClientValidation', 'safe', 'skipOnError', 'allowEmpty', 'caseSensitive'))) {
$preparedAttributes[$key] = CPropertyValue::ensureBoolean($value);
}
if ($key === 'except' || $key === 'on') {
if (!is_null($value)) {
$preparedAttributes[$key] = array_map('trim', explode(',', $value));
}
}
if ($key === 'criteria') {
if (is_string($value)) {
$value = trim($value);
}
$preparedAttributes[$key] = CPropertyValue::ensureArray($value);
}
}
return $preparedAttributes;
}
示例8: findByAttributeValue
private function findByAttributeValue($array, $attribute, $value)
{
$array = CPropertyValue::ensureArray($array);
foreach ($array as $key => $entry) {
if ($entry[$attribute] == $value) {
return $entry;
}
}
return false;
}
示例9: in_array
<?php
/**
* @var $authItem CAuthItem
*/
?>
<?php
if ($authItem->type == CAuthItem::TYPE_OPERATION) {
?>
<label>
<?php
echo CHtml::checkBox('role[' . $authItem->name . ']', in_array($authItem->name, CPropertyValue::ensureArray($role->data)));
?>
<?php
echo $authItem->description;
?>
</label>
<?php
} else {
?>
<p class="form-control-static">
<?php
echo CAuthItem::TYPE_ROLE == $authItem->type ? $authItem->name : $authItem->description;
?>
</p>
<?php
}