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


PHP IPAddress::setAddressFromArray方法代码示例

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


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

示例1: prepareInput

 /**
  * @param $input
  **/
 function prepareInput($input)
 {
     // In case of entity transfer, $input['network'] is not defined
     if (!isset($input['network']) && isset($this->fields['network'])) {
         $input['network'] = $this->fields['network'];
     }
     // In case of entity transfer, $input['gateway'] is not defined
     if (!isset($input['gateway']) && isset($this->fields['gateway'])) {
         $input['gateway'] = $this->fields['gateway'];
     }
     // If $this->fields["id"] is not set then, we are adding a new network
     // Or if $this->fields["network"] != $input["network"] we a updating the network
     $address = new IPAddress();
     $netmask = new IPNetmask();
     // Don't validate an empty network
     if (empty($input["network"])) {
         return array('error' => __('Invalid network address'), 'input' => false);
     }
     if (!isset($this->fields["id"]) || !isset($this->fields["network"]) || $input["network"] != $this->fields["network"]) {
         $network = explode("/", $input["network"]);
         if (count($network) != 2) {
             return array('error' => __('Invalid input format for the network'), 'input' => false);
         }
         if (!$address->setAddressFromString(trim($network[0]))) {
             return array('error' => __('Invalid network address'), 'input' => false);
         }
         if (!$netmask->setNetmaskFromString(trim($network[1]), $address->getVersion())) {
             return array('error' => __('Invalid subnet mask'), 'input' => false);
         }
         // After checking that address and netmask are valid, modify the address to be the "real"
         // network address : the first address of the network. This is not required for SQL, but
         // that looks better for the human
         self::computeNetworkRangeFromAdressAndNetmask($address, $netmask, $address);
         // Now, we look for already existing same network inside the database
         $params = array("address" => $address, "netmask" => $netmask);
         if (isset($this->fields["id"])) {
             $params["exclude IDs"] = $this->fields["id"];
         }
         if (isset($this->fields["entities_id"])) {
             $entities_id = $this->fields["entities_id"];
         } else {
             if (isset($input["entities_id"])) {
                 $entities_id = $input["entities_id"];
             } else {
                 $entities_id = -1;
             }
         }
         // TODO : what is the best way ? recursive or not ?
         $sameNetworks = self::searchNetworks("equals", $params, $entities_id, false);
         // Check unicity !
         if ($sameNetworks && count($sameNetworks) > 0) {
             return array('error' => __('Network already defined in visible entities'), 'input' => false);
         }
         // Then, update $input to reflect the network and the netmask
         $input = $address->setArrayFromAddress($input, "version", "address", "address");
         $input = $netmask->setArrayFromAddress($input, "", "netmask", "netmask");
         // We check to see if the network is modified
         $previousAddress = new IPAddress();
         $previousAddress->setAddressFromArray($this->fields, "version", "address", "address");
         $previousNetmask = new IPNetmask();
         $previousNetmask->setAddressFromArray($this->fields, "version", "netmask", "netmask");
         if ($previousAddress->equals($address) && $previousNetmask->equals($netmask)) {
             $this->networkUpdate = false;
         } else {
             $this->networkUpdate = true;
         }
     } else {
         // If netmask and address are not modified, then, load them from DB to check the validity
         // of the gateway
         $this->networkUpdate = false;
         $address->setAddressFromArray($this->fields, "version", "address", "address");
         $netmask->setAddressFromArray($this->fields, "version", "netmask", "netmask");
         $entities_id = $this->fields['entities_id'];
     }
     // Update class for the CommonImplicitTree update ...
     $this->data_for_implicit_update = array('address' => $address, 'netmask' => $netmask, 'entities_id' => $entities_id);
     $returnValue = array();
     // If the gateway has been altered, or the network information (address or netmask) changed,
     // then, we must revalidate the gateway !
     if (!isset($this->fields["gateway"]) || $input["gateway"] != $this->fields["gateway"] || $this->networkUpdate) {
         $gateway = new IPAddress();
         if (!empty($input["gateway"])) {
             if (!$gateway->setAddressFromString($input["gateway"]) || !self::checkIPFromNetwork($gateway, $address, $netmask)) {
                 $returnValue['error'] = __('Invalid gateway address');
                 if (!empty($this->fields["gateway"])) {
                     if (!$gateway->setAddressFromString($this->fields["gateway"]) || !self::checkIPFromNetwork($gateway, $address, $netmask)) {
                         $gateway->disableAddress();
                     }
                 } else {
                     $gateway->disableAddress();
                 }
             }
         }
         $input = $gateway->setArrayFromAddress($input, "", "gateway", "gateway");
     }
     $returnValue['input'] = $input;
     return $returnValue;
//.........这里部分代码省略.........
开发者ID:kipman,项目名称:glpi,代码行数:101,代码来源:ipnetwork.class.php


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