本文整理汇总了PHP中CMap::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::add方法的具体用法?PHP CMap::add怎么用?PHP CMap::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMap
的用法示例。
在下文中一共展示了CMap::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addAPIKey
/**
*
* Adds a Google API key to collection
* @param string $domain
* @param string $key
*/
public function addAPIKey($domain, $key)
{
if (null === $this->_keys) {
$this->_keys = new CMap();
}
$this->_keys->add($domain, $key);
}
示例2: locate
/**
*
* Locates IP information
* @param string $ip address. If null, it will locate the IP of request
*/
public function locate($ip = null)
{
if (null === $ip) {
$ip = $_SERVER['REMOTE_ADDR'];
}
$host = str_replace('{IP}', $ip, $this->_service);
$host = str_replace('{CURRENCY}', $this->_currency, $host);
$response = $this->fetch($host);
if (!is_null($response) && is_array($response)) {
$this->_data->mergeWith($response);
$this->_data->add('ip', $ip);
return true;
}
return true;
}
示例3: addItem
/**
*
* Add a FeedItem to the main class
*
* @param object instance of EFeedItemAbstract class
*/
public function addItem(EFeedItemAbstract $item)
{
if (null === $this->feedElements->itemAt('items')) {
$this->feedElements->add('items', new CTypedList('EFeedItemAbstract'));
}
$this->feedElements->itemAt('items')->add($item);
}
示例4: add
/**
* Adds an item into the map.
* This method overrides the parent implementation by
* checking the item to be inserted is of certain type.
* @param integer $index the specified position.
* @param mixed $item new item
* @throws CException If the index specified exceeds the bound,
* the map is read-only or the element is not of the expected type.
*/
public function add($index, $item)
{
if ($item instanceof $this->_type) {
parent::add($index, $item);
} else {
throw new CException(Yii::t('yii', 'CTypedMap<{type}> can only hold objects of {type} class.', array('{type}' => $this->_type)));
}
}
示例5: __set
/**
* @since v1.0.8
*/
public function __set($name, $value)
{
if ($this->hasEmbeddedDocuments() && isset(self::$_embeddedConfig[get_class($this)][$name])) {
if (is_array($value)) {
// Late creation of embedded documents on first access
if (is_null($this->_embedded->itemAt($name))) {
$docClassName = self::$_embeddedConfig[get_class($this)][$name];
$doc = new $docClassName($this->getScenario());
$doc->setOwner($this);
$this->_embedded->add($name, $doc);
}
return $this->_embedded->itemAt($name)->attributes = $value;
} else {
if ($value instanceof EMongoEmbeddedDocument) {
return $this->_embedded->add($name, $value);
}
}
} else {
parent::__set($name, $value);
}
}
示例6: add
/**
* Adds an item to the collection.
* This method overrides the parent implementation to ensure
* only configuration arrays, strings, or {@link CFormElement} objects
* can be stored in this collection.
* @param mixed key
* @param mixed value
* @throws CException if the value is invalid.
*/
public function add($key, $value)
{
if (is_array($value)) {
if (is_string($key)) {
$value['name'] = $key;
}
if ($this->_forButtons) {
$class = $this->_form->buttonElementClass;
$element = new $class($value, $this->_form);
} else {
if (!isset($value['type'])) {
$value['type'] = 'text';
}
if ($value['type'] === 'string') {
unset($value['type'], $value['name']);
$element = new CFormStringElement($value, $this->_form);
} else {
if (!strcasecmp(substr($value['type'], -4), 'form')) {
$class = $value['type'] === 'form' ? get_class($this->_form) : Yii::import($value['type']);
$element = new $class($value, null, $this->_form);
} else {
$class = $this->_form->inputElementClass;
$element = new $class($value, $this->_form);
}
}
}
} else {
if ($value instanceof CFormElement) {
if (property_exists($value, 'name') && is_string($key)) {
$value->name = $key;
}
$element = $value;
} else {
$element = new CFormStringElement(array('content' => $value), $this->_form);
}
}
parent::add($key, $element);
$this->_form->addedElement($key, $element, $this->_forButtons);
}
示例7: add
public function add($name, $cookie = null)
{
if ($name instanceof CHttpCookie) {
$cookieName = $name->name;
$cookieObject = $name;
} else {
$cookieName = (string) $name;
$cookieObject = $cookie;
}
if ($cookieObject instanceof CHttpCookie) {
$this->remove($cookieName);
parent::add($cookieName, $cookieObject);
if ($this->_initialized) {
$this->addCookie($cookieObject);
}
} else {
throw new CException(Yii::t('yii', 'CHttpCookieCollection can only hold CHttpCookie objects.'));
}
}
示例8: add
/**
* Adds an item into the map.
* This overrides the parent implementation by converting the key to lower case first if {@link caseSensitive} is false.
* @param mixed $key key
* @param mixed $value value
*/
public function add($key, $value)
{
if ($this->caseSensitive) {
parent::add($key, $value);
} else {
parent::add(strtolower($key), $value);
}
}
示例9: updateStored
/**
* Updates the position in the shopping cart
* If the position was previously added, then it will be updated in shopping cart,
* if the position was not previously in the cart, it will be added there.
* If the count of less than 1, the position will be deleted.
*
* @param IECartPosition $position
* @param int $quantity
*/
public function updateStored(IECartPosition $position, $quantity)
{
if ($this->objSectorCiudad !== null) {
$key = $position->getId();
$position->generate(array('objSectorCiudad' => $this->objSectorCiudad, 'codigoPerfil' => $this->codigoPerfil));
$position->setQuantityStored($quantity);
if ($position->getQuantity(true) + $position->getQuantity(false) < 1) {
$this->remove($key);
} else {
parent::add($key, $position);
}
$this->applyDiscounts();
$this->onUpdatePoistion(new CEvent($this));
$this->saveState();
return true;
}
return false;
}
示例10: getVisibleItems
public function getVisibleItems()
{
$visibleItems = new CMap();
foreach ($this->getItems() as $id => $item) {
if ($item->getVisible() === true) {
$visibleItems->add($id, $item);
}
}
return $visibleItems;
}
示例11: actionGetGroceryRate
public function actionGetGroceryRate()
{
$inquiry = new InquiryForm('api-rate-grocery');
$req = Yii::app()->request;
$inquiryMap = new CMap();
$inquiryMap->add('receiver_postal', $req->getQuery('receiver_postal'));
$inquiryMap->add('service_code', $req->getQuery('service_code'));
$inquiry->setAttributes($inquiryMap->toArray());
if (!$inquiry->validate()) {
echo CJSON::encode($this->statusError($inquiry->getErrors()));
Yii::app()->end();
}
$service_code = ProductService::model()->findByAttributes(array('code' => strtoupper($inquiry->service_code)));
if (!$service_code instanceof ProductService) {
echo CJSON::encode($this->statusError('No Service Available'));
Yii::app()->end();
} else {
if ($service_code->code != 'LSX' && $service_code->code != 'HRX') {
echo CJSON::encode($this->statusError('This service is not available'));
Yii::app()->end();
}
}
$routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
if ($routing instanceof IntraCityRouting) {
$area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
if (!$area) {
echo CJSON::encode($this->statusError('No Available Service'));
Yii::app()->end();
}
$rates = RateCity::getCityRate(ProductService::ProductCityCourier, $routing->code, 5);
$rate = array();
foreach ($rates as $key) {
if ($key['service_code'] == $inquiry->service_code) {
$rate = $key;
}
}
$product = 'City Courier';
echo CJSON::encode($this->statusSuccess(array('service_type' => $product, 'rate' => $rate)));
Yii::app()->end();
} else {
$result = array('status' => 'success', 'result' => $data);
}
echo CJSON::encode($result);
Yii::app()->end();
}
示例12: put
/**
* Add item to the favorite
* @param IEFavoritePosition $position
*/
public function put(IEFavoritePosition $position)
{
parent::add($position->getId(), $position->id);
$this->saveState();
}
示例13: getBlocks
/**
*
*/
public function getBlocks($regionId, $visibleOnly = true)
{
$instance = self::getInstance();
$blocks = new CMap();
if ($instance->regions->contains($regionId)) {
foreach ($instance->regions[$regionId] as $blockId => $block) {
if ($visibleOnly) {
if ($block->getVisible() === false) {
continue;
}
}
$blocks->add($blockId, $block);
}
}
return self::sortBlocks($blocks);
}
示例14: updateCount
public function updateCount(IECartPosition $position, $count)
{
if (!$position instanceof CComponent) {
throw new InvalidArgumentException('invalid argument 1, product must implement CComponent interface');
}
$key = $position->getId();
$position->detachBehavior("CartPosition");
$position->attachBehavior("CartPosition", new ECartPositionBehaviour());
$position->setRefresh($this->refresh);
$position->count = $count;
$position->calculatePriceForThisCount();
parent::add($key, $position);
$this->applyDiscounts();
$this->onUpdatePosition(new CEvent($this));
$this->saveState();
}
示例15: update
/**
* Updates the position in the shopping cart
* If position was previously added, then it will be updated in shopping cart,
* if position was not previously in the cart, it will be added there.
* If count is less than 1, the position will be deleted.
*
* @param IECartPosition $position
* @param int $quantity
*/
public function update(IECartPosition $position, $quantity)
{
if (!$position instanceof CComponent) {
throw new InvalidArgumentException('invalid argument 1, product must implement CComponent interface');
}
$key = $position->getId();
$position->detachBehavior("CartPosition");
$position->attachBehavior("CartPosition", new ECartPositionBehaviour());
$position->setRefresh($this->refresh);
$position->setQuantity($quantity);
if ($position->getQuantity() < 1) {
$this->remove($key);
} else {
parent::add($key, $position);
}
$this->applyDiscounts();
$this->onUpdatePosition(new CEvent($this));
$this->saveState();
}