示例#1
0
文件: form.php 项目: mage2pro/core
/**
 * 2016-01-29
 * @param AE|E $e
 * @param string|null $key [optional]
 * @param string|null|callable $default [optional]
 * @return string|null|array(string => mixed)
 */
function df_fe_fc(AE $e, $key = null, $default = null)
{
    /** @var array(string => mixed) $result */
    $result = df_fe_top($e)->getFieldConfig();
    df_assert_array($result);
    return $key ? dfa($result, $key, $default) : $result;
}
示例#2
0
 /**
  * @return array
  */
 private function getAsOptionArray()
 {
     if (!isset($this->_asOptionArray)) {
         /** @var array $optionCurrenciesAll */
         $optionCurrenciesAll = Mage::app()->getLocale()->getOptionCurrencies();
         df_assert_array($optionCurrenciesAll);
         /** @var array $optionCurrencyMap */
         $optionCurrencyMap = array_combine(df_column($optionCurrenciesAll, 'value'), df_column($optionCurrenciesAll, 'label'));
         df_assert_array($optionCurrencyMap);
         /** @var array $result */
         $result = array();
         foreach (self::getAllowedCurrencies() as $currencyCode) {
             /** @var string $currencyCode */
             /** @var string|null $label  */
             $label = df_a($optionCurrencyMap, $currencyCode);
             if (!is_null($label)) {
                 $result[] = array('value' => $currencyCode, 'label' => $label);
             }
         }
         df_assert_array($result);
         $this->_asOptionArray = $result;
     }
     df_result_array($this->_asOptionArray);
     return $this->_asOptionArray;
 }
示例#3
0
 /**
  * @return array
  */
 private function getPost()
 {
     if (!isset($this->_post)) {
         /** @var array $result  */
         $result = df()->request()->filterDates(df()->request()->getController()->getRequest()->getPost(), array('from_date', 'to_date'));
         df_assert_array($result);
         $this->_post = $result;
     }
     df_result_array($this->_post);
     return $this->_post;
 }
示例#4
0
 /**
  * @return array
  */
 public function getDocumentData()
 {
     /** @var array $attributes */
     $attributes = array('id' => $this->getProduct()->getId(), 'available' => df_output()->convertBooleanToString($this->getProduct()->isInStock()));
     df_assert_array($attributes);
     if ($this->hasVendorInfo()) {
         $attributes['type'] = 'vendor.model';
     }
     /** @var array $result */
     $result = array(Df_Varien_Simplexml_Element::KEY__ATTRIBUTES => $attributes, Df_Varien_Simplexml_Element::KEY__VALUE => $this->getValue());
     df_result_array($result);
     return $result;
 }
示例#5
0
 /**
  * @return array
  */
 private function getCategoryIds()
 {
     if (!isset($this->_categoryIds)) {
         /** @var array $result  */
         $result = array();
         foreach ($this->getProducts() as $product) {
             /** @var Mage_Catalog_Model_Product $product */
             df_assert($product instanceof Mage_Catalog_Model_Product);
             $result = array_merge($result, $product->getCategoryIds());
         }
         df_assert_array($result);
         $this->_categoryIds = $result;
     }
     df_result_array($this->_categoryIds);
     return $this->_categoryIds;
 }
示例#6
0
文件: Text.php 项目: mage2pro/core
 /**
  * @param string|string[]|array(string => string) $text
  * @param string $type [optional]
  * @return string|string[]
  */
 public function quote($text, $type = self::QUOTE__RUSSIAN)
 {
     if ('"' === $type) {
         $type = self::QUOTE__DOUBLE;
     } else {
         if ("'" === $type) {
             $type = self::QUOTE__SINGLE;
         }
     }
     /** @var array(string => string[]) $quotesMap */
     static $quotesMap = [self::QUOTE__DOUBLE => ['"', '"'], self::QUOTE__RUSSIAN => ['«', '»'], self::QUOTE__SINGLE => ['\'', '\'']];
     /** @var string[] $quotes */
     $quotes = dfa($quotesMap, $type);
     if (!is_array($quotes)) {
         df_error('Неизвестный тип кавычки «%s».', $type);
     }
     df_assert_array($quotes);
     /**
      * 2016-11-13
      * Обратите внимание на красоту решения: мы «склеиваем кавычки»,
      * используя в качестве промежуточного звена исходную строку.
      * @param string $text
      * @return string
      */
     $f = function ($text) use($quotes) {
         return implode($text, $quotes);
     };
     return !is_array($text) ? $f($text) : array_map($f, $text);
 }
示例#7
0
 /**
  * 2015-12-08
  * @return array(string => int[])
  */
 private function datumPoints()
 {
     if (!$this->_datumPoints) {
         if (file_exists($this->pathToDatumPoints())) {
             try {
                 $this->_datumPoints = df_json_decode(df_media_read($this->pathToDatumPoints()));
             } catch (\Exception $e) {
                 df_log($e->getMessage());
             }
         }
         if (!$this->_datumPoints) {
             $this->create();
             df_assert_array($this->_datumPoints);
         }
     }
     return $this->_datumPoints;
 }
示例#8
0
文件: X.php 项目: mage2pro/core
 /**
  * @param array(string => mixed) $array
  * @param string[]|bool $wrapInCData [optional]
  * @return X
  */
 public function importArray(array $array, $wrapInCData = [])
 {
     foreach ($array as $key => $value) {
         /** @var string $key */
         /** @var mixed $value */
         if ($value instanceof X) {
             /**
             * 2016-08-31
             * Случай, который отсутствовал в Российсеой сборке Magento:
             					'Payment' => [
             						df_xml_node('TxnList', ['count' => 1], [
             							df_xml_node('Txn', ['ID' => 1], [
             								'amount' => 200
             								,'purchaseOrderNo' => 'test'
             								,'txnID' => '009887'
             								,'txnSource' => 23
             								,'txnType' => 4
             							])
             						])
             					]
             *
             					<Payment>
             						<TxnList count="1">
             							<Txn ID="1">
             								<txnType>4</txnType>
             								<txnSource>23</txnSource>
             								<amount>200</amount>
             								<purchaseOrderNo>test</purchaseOrderNo>
             								<txnID>009887</txnID>
             							</Txn>
             						</TxnList>
             					</Payment>
             */
             $this->addChildX($value);
         } else {
             if (!is_array($value)) {
                 $this->importString($key, $value, $wrapInCData);
             } else {
                 if (df_is_assoc($value) || array_filter($value, function ($i) {
                     return $i instanceof X;
                 })) {
                     /** @var X $childNode */
                     $childNode = $this->addChild($key);
                     /** @var array|null $childData */
                     $childData = $value;
                     // Данный программный код позволяет импортировать атрибуты тэгов
                     /** @var array(string => string)|null $attributes $attributes */
                     $attributes = dfa($value, self::ATTR);
                     if (!is_null($attributes)) {
                         df_assert_array($attributes);
                         $childNode->addAttributes($attributes);
                         /**
                          * Если $value содержит атрибуты,
                          * то дочерние значения должны содержаться
                          * не непосредственно в $value, а в подмассиве с ключём self::CONTENT
                          */
                         $childData = dfa($value, self::CONTENT);
                     }
                     if (!is_null($childData)) {
                         /**
                         * $childData запросто может не быть массивом.
                         * Например, в такой ситуации:
                         						(
                         							[_attributes] => Array
                         								(
                         									[Код] => 796
                         									[НаименованиеПолное] => Штука
                         									[МеждународноеСокращение] => PCE
                         								)
                         							[_value] => шт
                         						)
                         * Здесь $childData — это «шт».
                         */
                         if (is_array($childData)) {
                             $childNode->importArray($childData, $wrapInCData);
                         } else {
                             $childNode->importString($key = null, $childData, $wrapInCData);
                         }
                     }
                 } else {
                     /**
                     * Данный код позволяет импортировать структуры с повторяющимися тегами.
                     * Например, нам надо сформировать такой документ:
                     					<АдресРегистрации>
                     						<АдресноеПоле>
                     							<Тип>Почтовый индекс</Тип>
                     							<Значение>127238</Значение>
                     						</АдресноеПоле>
                     						<АдресноеПоле>
                     							<Тип>Улица</Тип>
                     							<Значение>Красная Площадь</Значение>
                     						</АдресноеПоле>
                     					</АдресРегистрации>
                     *
                     * Для этого мы вызываем:
                     *
                     					$this->getDocument()
                     						->importArray(
                     							array(
                     				'АдресРегистрации' =>
                     									array(
                     										'АдресноеПоле' =>
                     											array(
                     												array(
                     													'Тип' => 'Почтовый индекс'
                     													,'Значение' => '127238'
                     												)
                     												,array(
                     													'Тип' => 'Улица'
                     													,'Значение' => 'Красная Площадь'
                     												)
                     											)
                     									)
                     							)
                     						)
                     					;
                     *
                     */
                     foreach ($value as $valueItem) {
                         /** @var array(string => mixed)|string $valueItem */
                         /**
                         * 2015-01-20
                         * Обратите внимание, что $valueItem может быть не только массивом, но и строкой.
                         * Например, такая структура:
                         						<Группы>
                         							<Ид>1</Ид>
                         							<Ид>1</Ид>
                         							<Ид>1</Ид>
                         						</Группы>
                         * кодируется так:
                         * array('Группы' => array('Ид' => array(1, 2, 3)))
                         */
                         $this->importArray([$key => $valueItem], $wrapInCData);
                     }
                 }
             }
         }
     }
     return $this;
 }