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


PHP Code::castArray方法代码示例

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


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

示例1: process

 /**
  * Synchronisiert eine Collection von (Datenbank-)Objekten mit einer Collection von Daten / Unique-Kriterien oder Exportieren Objekten
  *
  * Die $fromCollection ist die Collection der bereits hydrierten Objekte. (fertige Tags)
  * die $toCollection ist die noch nicht hydrierte Collection der Objekte die Objekte in $fromCollection repräsentieren (Tag Labels)
  * 
  * zur Hilfe werden zwei Funktionen benötigt.
  * Die hydrierFunktion erstellt aus den Daten asu $toCollection ein Objekt aus $fromCollection ( $label ===> Entity $tag )
  * die hash Funktion erstellt aus einem Objekt von $fromCollection einen Skalar ( Entity $tag => $id )
  *
  * Article und Test beispiel:
  *
  * $fromCollection = $article->getTags();
  * $toCollection = array('Tag1Name','Tag2Name','....');
  *
  * so ungefähr!! muss NULL zurückgeben nicht array
  * $hydrateUniqueObject = function (\stdClass $json) {
  *    return $em->createQueryBuilder()
  *      ->select('tag')->from('Entities\Tag')
  *      ->where('id = :id OR uniqueconstraint = :unique)
  *      ->setParameter(
  *         array(
  *           'id'=>$json->id,
  *           'unique'>$json->label
  *         )
  *       )
  *    ;
  * };
  *
  * $hashObject = function (Tag $tag) {
  *   return $tag->getIdentifier();
  * };
  *
  * @param ArrayCollection $dbCollection die Collection als fertige Objekte aus der Datenbank
  * @param collection $toCollection eine noch nicht hydrierte Collection von Objekten die Objekte in $fromCollection repräsentieren kann
  *
  * @return list($insert,$updates,$deletes) die jeweiligen listen von dispatchten events
  */
 public function process($fromCollection, $toCollection)
 {
     // wir haben keine Ahnung welche Objekte in der $fromCollection und welche in der $toCollection sind
     $fromCollection = \Psc\Code\Code::castArray($fromCollection);
     // damit wir eine copy machen
     $updates = $inserts = $deletes = array();
     $index = array();
     foreach ($toCollection as $toCollectionKey => $toObject) {
         $fromObject = $this->hydrateUniqueObject($toObject, $toCollectionKey);
         // kein objekt konnte hydriert werden
         if ($fromObject === NULL) {
             $inserts[] = $this->dispatchInsert($toObject, array('key' => $toCollectionKey));
             // inserts müssen nicht in den index, da sie nicht im universum gefunden wurden, können sie auch nicht in $fromCollection sein
         } else {
             // objekt hydriert, kann mit korrekter id sein oder matching unique-constraint
             $updates[] = $this->dispatchUpdate($fromObject, array('from' => $fromObject, 'to' => $toObject, 'key' => $toCollectionKey));
             $index[$this->hashObject($fromObject)] = TRUE;
         }
     }
     foreach ($fromCollection as $fromObject) {
         if (!array_key_exists($this->hashObject($fromObject), $index)) {
             // object ist weder ein insert noch ein update
             $deletes[] = $this->dispatchDelete($fromObject);
         }
     }
     return array($inserts, $updates, $deletes);
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:65,代码来源:HydrationCollectionSynchronizer.php

示例2: validate

 public function validate($data)
 {
     if ($data === NULL) {
         throw EmptyDataException::factory(array());
     }
     $data = Code::castArray($data);
     if (count($data) == 0) {
         throw EmptyDataException::factory(array());
     }
     if (count($data) > 0) {
         return $data;
     }
     throw new \Psc\Exception('Konnte nicht validiert werden');
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:14,代码来源:ArrayValidatorRule.php

示例3: listStrings

 /**
  * @var mixed $print Closure|String wenn ein String wird dies als Attribute gesehen welches mit get$print() vom Objekt geladen werden kann
  */
 public static function listStrings($collection, $sep = ', ', $andsep = NULL, Closure $formatter = NULL)
 {
     $collection = Code::castArray($collection);
     $cnt = count($collection);
     if (isset($andsep) && $cnt >= 2) {
         $last = array_pop($collection);
     } else {
         $andsep = NULL;
     }
     $formatter = $formatter ?: function ($item) {
         return (string) $item;
     };
     $ret = A::implode($collection, $sep, $formatter);
     if (isset($andsep) && $last != NULL) {
         $ret .= $andsep . $formatter($last);
     }
     return $ret;
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:21,代码来源:Helper.php

示例4: debugCollection

 public static function debugCollection($collection, $glue = "\n", $label = NULL)
 {
     $ret = $label ? 'Collection ' . $label . $glue : NULL;
     if (count($collection) === 0) {
         $ret .= '[leere Collection]';
     } else {
         $ret .= \Webforge\Common\ArrayUtil::implode(Code::castArray($collection), $glue, function ($item, $key) {
             return sprintf('[%s] %s', $key, \Psc\Doctrine\Helper::debugEntity($item));
         });
     }
     return $ret;
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:12,代码来源:Helper.php


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