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


PHP Package::get方法代码示例

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


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

示例1: array

<?php

/**
 * Registry
 */
class Package
{
    protected static $data = array();
    public static function set($key, $value)
    {
        self::$data[$key] = $value;
    }
    public static function get($key)
    {
        return isset(self::$data[$key]) ? self::$data[$key] : null;
    }
    public static function removeObject($key)
    {
        if (array_key_exists($key, self::$data)) {
            unset(self::$data[$key]);
        }
    }
}
Package::set('ACL', 'Assess Control List');
Package::set('DISP', 'Dispatcher');
var_dump(Package::get('ACL'));
var_dump(Package::get('DISP'));
Package::removeObject('ACL');
var_dump(Package::get('ACL'));
开发者ID:rainbowzl7,项目名称:design-patterns-in-php,代码行数:29,代码来源:Registry.php

示例2: getVolumePackagesByGross

 /**
  * [getVolumePackagesByGross description]
  * @return [type] [description]
  */
 public function getVolumePackagesByGross()
 {
     /**
      * Storage
      */
     $itemVolumeTotal = 0;
     $itemWeightTotal = 0;
     $final_packages = array();
     $items = $this->getItems();
     $packageOptions = $this->getPackageOptions();
     /**
      * Total Items
      */
     for ($i = 0; $i < count($items); $i++) {
         $itemVolumeTotal += $items[$i]->get('volume');
         $itemWeightTotal += $items[$i]->get('weight');
     }
     /**
      * Calculate based on Package Dimensions
      */
     if ($packageOptions && ($itemVolumeTotal || $itemWeightTotal)) {
         $itemVolumeRemain = $itemVolumeTotal;
         $itemWeightRemain = $itemWeightTotal;
         $itemWeightSizeRatio = $itemVolumeRemain / $itemWeightRemain;
         do {
             // Prepare
             $package_found = false;
             // Fit into New Package
             if (!$package_found) {
                 foreach ($packageOptions as $key => $package) {
                     if ($package->get('volume') >= $itemVolumeRemain && $package->get('weight') >= $itemWeightRemain) {
                         $new_package = new Package($package);
                         $new_package->set('volume_used', $itemVolumeRemain);
                         $new_package->set('weight_used', $itemWeightRemain);
                         $final_packages[] = $new_package;
                         $itemVolumeRemain = 0;
                         $itemWeightRemain = 0;
                         $package_found = true;
                         break;
                     }
                 }
             }
             // Split and place into largest package
             if (!$package_found) {
                 $new_package = new Package(end($packageOptions));
                 $package_maxVolume = $new_package->get('volume');
                 $package_maxWeight = $new_package->get('weight');
                 $package_ratio = $package_maxVolume / $package_maxWeight;
                 $newVolumeUsed = null;
                 $newWeightUsed = null;
                 $isOverVolume = $itemVolumeRemain > $package_maxVolume;
                 $isOverWeight = $itemWeightRemain > $package_maxWeight;
                 if ($isOverVolume || $isOverWeight) {
                     if ($itemWeightSizeRatio > $package_ratio) {
                         $newVolumeUsed = $isOverVolume ? $package_maxVolume : $itemVolumeRemain;
                         $newWeightUsed = round($newVolumeUsed / $itemWeightSizeRatio, 2, PHP_ROUND_HALF_DOWN);
                         if ($newWeightUsed > $package_maxWeight) {
                             $newWeightUsed = $package_maxWeight;
                             $newVolumeUsed = round($newWeightUsed * $itemWeightSizeRatio, 2, PHP_ROUND_HALF_DOWN);
                         }
                     } else {
                         $newWeightUsed = $isOverWeight ? $package_maxWeight : $itemWeightRemain;
                         $newVolumeUsed = round($newWeightUsed * $itemWeightSizeRatio, 2, PHP_ROUND_HALF_DOWN);
                         if ($newVolumeUsed > $package_maxVolume) {
                             $newVolumeUsed = $package_maxVolume;
                             $newWeightUsed = round($newVolumeUsed / $itemWeightSizeRatio, 2, PHP_ROUND_HALF_DOWN);
                         }
                     }
                 }
                 if (is_null($netVolumeUsed) || $netVolumeUsed > $itemVolumeRemain) {
                     $netVolumeUsed = $itemVolumeRemain;
                 }
                 if (is_null($newWeightUsed) || $newWeightUsed > $itemWeightRemain) {
                     $newWeightUsed = $itemWeightRemain;
                 }
                 $new_package->set('volume_used', $newVolumeUsed > 0 ? $newVolumeUsed : 1);
                 $new_package->set('weight_used', $newWeightUsed > 0 ? $newWeightUsed : 1);
                 $final_packages[] = $new_package;
                 $itemVolumeRemain -= $newVolumeUsed;
                 $itemWeightRemain -= $newWeightUsed;
                 $package_found = true;
             }
         } while ($package_found && ($itemVolumeRemain || $itemWeightRemain));
     }
     /**
      * Complete
      */
     return $final_packages;
 }
开发者ID:WebuddhaInc,项目名称:BinPacker,代码行数:93,代码来源:Packer.php


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