当前位置: 首页>>代码示例>>PHP>>正文


PHP Piwik::isAssociativeArray方法代码示例

本文整理汇总了PHP中Piwik\Piwik::isAssociativeArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik::isAssociativeArray方法的具体用法?PHP Piwik::isAssociativeArray怎么用?PHP Piwik::isAssociativeArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Piwik\Piwik的用法示例。


在下文中一共展示了Piwik::isAssociativeArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: renderArray

 public function renderArray($array)
 {
     $result = parent::renderArray($array);
     // if $array is a simple associative array, remove the JSON root array that is added by renderDataTable
     if (!empty($array) && Piwik::isAssociativeArray($array) && !Piwik::isMultiDimensionalArray($array)) {
         $result = substr($result, 1, strlen($result) - 2);
     }
     return $result;
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:9,代码来源:Json2.php

示例2: renderArray

 public function renderArray($array)
 {
     if (Piwik::isMultiDimensionalArray($array)) {
         $jsonRenderer = Renderer::factory('json');
         $jsonRenderer->setTable($array);
         $result = $jsonRenderer->render();
         return $this->applyJsonpIfNeeded($result);
     }
     $result = $this->renderDataTable($array);
     // if $array is a simple associative array, remove the JSON root array that is added by renderDataTable
     if (!empty($array) && Piwik::isAssociativeArray($array) && !Piwik::isMultiDimensionalArray($array)) {
         $result = substr($result, 1, strlen($result) - 2);
     }
     return $result;
 }
开发者ID:piwik,项目名称:piwik,代码行数:15,代码来源:Json.php

示例3: testIsAssociativeArray

 /**
  * @dataProvider getIsAssociativeArrayTestCases
  */
 public function testIsAssociativeArray($array, $expected)
 {
     $this->assertEquals($expected, Piwik::isAssociativeArray($array));
 }
开发者ID:TensorWrenchOSS,项目名称:piwik,代码行数:7,代码来源:PiwikTest.php

示例4: shouldWrapArrayBeforeRendering

 /**
  * Returns true if an array should be wrapped before rendering. This is used to
  * mimic quirks in the old rendering logic (for backwards compatibility). The
  * specific meaning of 'wrap' is left up to the Renderer. For XML, this means a
  * new <row> node. For JSON, this means wrapping in an array.
  *
  * In the old code, arrays were added to new DataTable instances, and then rendered.
  * This transformation wrapped associative arrays except under certain circumstances,
  * including:
  *  - single element (ie, array('nb_visits' => 0))   (not wrapped for some renderers)
  *  - empty array (ie, array())
  *  - array w/ arrays/DataTable instances as values (ie,
  *            array('name' => 'myreport',
  *                  'reportData' => new DataTable())
  *        OR  array('name' => 'myreport',
  *                  'reportData' => array(...)) )
  *
  * @param array $array
  * @param bool $wrapSingleValues Whether to wrap array('key' => 'value') arrays. Some
  *                               renderers wrap them and some don't.
  * @param bool|null $isAssociativeArray Whether the array is associative or not.
  *                                      If null, it is determined.
  * @return bool
  */
 protected static function shouldWrapArrayBeforeRendering($array, $wrapSingleValues = true, $isAssociativeArray = null)
 {
     if (empty($array)) {
         return false;
     }
     if ($isAssociativeArray === null) {
         $isAssociativeArray = Piwik::isAssociativeArray($array);
     }
     $wrap = true;
     if ($isAssociativeArray) {
         // we don't wrap if the array has one element that is a value
         $firstValue = reset($array);
         if (!$wrapSingleValues && count($array) === 1 && (!is_array($firstValue) && !is_object($firstValue))) {
             $wrap = false;
         } else {
             foreach ($array as $value) {
                 if (is_array($value) || is_object($value)) {
                     $wrap = false;
                     break;
                 }
             }
         }
     } else {
         $wrap = false;
     }
     return $wrap;
 }
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:51,代码来源:Renderer.php

示例5: renderArray

 /**
  * Renders an array as XML.
  *
  * @param array $array The array to render.
  * @param string $prefixLines The string to prefix each line in the output.
  * @return string
  */
 private function renderArray($array, $prefixLines)
 {
     $isAssociativeArray = Piwik::isAssociativeArray($array);
     // check if array contains arrays, and if not wrap the result in an extra <row> element
     // (only check if this is the root renderArray call)
     // NOTE: this is for backwards compatibility. before, array's were added to a new DataTable.
     // if the array had arrays, they were added as multiple rows, otherwise it was treated as
     // one row. removing will change API output.
     $wrapInRow = $prefixLines === "\t" && self::shouldWrapArrayBeforeRendering($array, $wrapSingleValues = false, $isAssociativeArray);
     // render the array
     $result = "";
     if ($wrapInRow) {
         $result .= "{$prefixLines}<row>\n";
         $prefixLines .= "\t";
     }
     foreach ($array as $key => $value) {
         // based on the type of array & the key, determine how this node will look
         if ($isAssociativeArray) {
             $keyIsInvalidXmlElement = is_numeric($key) || is_numeric($key[0]);
             if ($keyIsInvalidXmlElement) {
                 $prefix = "<row key=\"{$key}\">";
                 $suffix = "</row>";
                 $emptyNode = "<row key=\"{$key}\"/>";
             } else {
                 if (strpos($key, '=') !== false) {
                     list($keyAttributeName, $key) = explode('=', $key, 2);
                     $prefix = "<row {$keyAttributeName}=\"{$key}\">";
                     $suffix = "</row>";
                     $emptyNode = "<row {$keyAttributeName}=\"{$key}\">";
                 } else {
                     $prefix = "<{$key}>";
                     $suffix = "</{$key}>";
                     $emptyNode = "<{$key} />";
                 }
             }
         } else {
             $prefix = "<row>";
             $suffix = "</row>";
             $emptyNode = "<row/>";
         }
         // render the array item
         if (is_array($value)) {
             $result .= $prefixLines . $prefix . "\n";
             $result .= $this->renderArray($value, $prefixLines . "\t");
             $result .= $prefixLines . $suffix . "\n";
         } else {
             if ($value instanceof DataTable || $value instanceof Map) {
                 if ($value->getRowsCount() == 0) {
                     $result .= $prefixLines . $emptyNode . "\n";
                 } else {
                     $result .= $prefixLines . $prefix . "\n";
                     if ($value instanceof Map) {
                         $result .= $this->renderDataTableMap($value, $this->getArrayFromDataTable($value), $prefixLines);
                     } else {
                         if ($value instanceof Simple) {
                             $result .= $this->renderDataTableSimple($this->getArrayFromDataTable($value), $prefixLines);
                         } else {
                             $result .= $this->renderDataTable($this->getArrayFromDataTable($value), $prefixLines);
                         }
                     }
                     $result .= $prefixLines . $suffix . "\n";
                 }
             } else {
                 $xmlValue = self::formatValueXml($value);
                 if (strlen($xmlValue) != 0) {
                     $result .= $prefixLines . $prefix . $xmlValue . $suffix . "\n";
                 } else {
                     $result .= $prefixLines . $emptyNode . "\n";
                 }
             }
         }
     }
     if ($wrapInRow) {
         $result .= substr($prefixLines, 0, strlen($prefixLines) - 1) . "</row>\n";
     }
     return $result;
 }
开发者ID:brienomatty,项目名称:elmsln,代码行数:84,代码来源:Xml.php


注:本文中的Piwik\Piwik::isAssociativeArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。