本文整理汇总了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'));
示例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;
}