/** * 设置/获取 配置 * array( * 'HelloWorld' => array( * 'addresses' => array( * '127.0.0.1:9090', * '127.0.0.2:9090', * '127.0.0.3:9090', * ), * ), * 'UserInfo' => array( * 'addresses' => array( * '127.0.0.1:9090' * ), * ), * ) * @param array $config * @return array */ public static function config(array $config = array()) { if (!empty($config)) { // 赋值 self::$config = $config; // 注册address到AddressManager $address_map = array(); foreach (self::$config as $key => $item) { $address_map[$key] = $item['addresses']; } AddressManager::config($address_map); } return self::$config; }
/** * 获取一个实例 * @return instance */ protected function __instance() { // 获取一个服务端节点地址 $address = AddressManager::getOneAddress($this->serviceName); list($ip, $port) = explode(':', $address); // Transport $socket = new \Thrift\Transport\TSocket($ip, $port); //timeout config $socket->setSendTimeout($this->sendTimeout); $socket->setRecvTimeout($this->recvTimeout); $transport_name = ThriftClient::getTransport($this->serviceName); $transport = new $transport_name($socket); // Protocol $protocol_name = ThriftClient::getProtocol($this->serviceName); $protocol = new $protocol_name($transport); try { $transport->open(); } catch (\Exception $e) { // 无法连上,则踢掉这个地址 AddressManager::kickAddress($address); throw $e; } // 客户端类名称 $class_name = ThriftClient::getServiceDir($this->serviceName); // 类不存在则报出异常 if (!class_exists($class_name)) { throw new \Exception("Class {$class_name} not found in directory {$service_dir}"); } // 初始化一个实例 return new $class_name($protocol); }
<?php class AddressManager { public $title = "default product"; public $producerMainName = "main name"; public $producerFirstNmae = "first name"; public $price = 0; private $addresses = array("209.131.36.159", "74.125.19.106"); public function outputAddresses($resolve) { foreach ($this->addresses as $address) { print $address . "<br>"; if ($resolve) { // gethostbyaddr()让互联网主机名对应于给定的IP地址 print "(" . gethostbyaddr($address) . ")"; } print "<br>"; } } } $settings = simplexml_load_file("settings.xml"); $manager = new AddressManager(); $manager->outputAddresses((string) $settings->resolvedomains);
/** * 获取一个实例 * @return instance */ protected function __instance() { // 获取一个服务端节点地址 $address = AddressManager::getOneAddress($this->serviceName); list($ip, $port) = explode(':', $address); // Transport $socket = new \Thrift\Transport\TSocket($ip, $port); $transport_name = ThriftClient::getTransport($this->serviceName); $transport = new $transport_name($socket); // Protocol $protocol_name = ThriftClient::getProtocol($this->serviceName); $protocol = new $protocol_name($transport); try { $transport->open(); } catch (\Exception $e) { // 无法连上,则踢掉这个地址 AddressManager::kickAddress($address); throw $e; } // 客户端类名称 $class_name = "\\Services\\" . $this->serviceName . "\\" . $this->serviceName . "Client"; // 类不存在则尝试加载 if (!class_exists($class_name)) { $service_dir = $this->includeFile(); if (!class_exists($class_name)) { throw new \Exception("Class {$class_name} not found in directory {$service_dir}"); } } // 初始化一个实例 return new $class_name($protocol); }
<?php include './protect.php'; include_once "./Manager/CustomerManager.php"; include_once "./Manager/AddressManager.php"; include_once "./Manager/ConnectionManager.php"; $customerMgr = new CustomerManager(); $addressMgr = new AddressManager(); $customer = $customerMgr->getCustomer($_SESSION["userid"]); $customer_credits = $customerMgr->getCredit($_SESSION["userid"]); $customer_id = $customer['customer_id']; $username = substr($customer_id, 0, strpos($customer_id, "@")); $invitation_link = $_SERVER['SERVER_NAME'] . '/allocacoc/' . $customer['invitation_link']; $address_list = $addressMgr->getAddress($customer_id); /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <script type="text/javascript" src="./public_html/js/ZeroClipboard.js" ></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> <link rel="stylesheet" href="./public_html/css/main.css"> <style> #credit_content { position: relative;
return true; } /** * 释放锁 * @return bool */ public static function releaseMutex() { ($fd = self::getSemFd()) && sem_release($fd); return true; } } // ================ 以下是测试代码 ====================== if (PHP_SAPI == 'cli' && isset($argv[0]) && $argv[0] == basename(__FILE__)) { AddressManager::config(array('HelloWorld' => array('127.0.0.1:9090', '127.0.0.2:9090', '127.0.0.3:9090'), 'HelloWorldService' => array('127.0.0.4:9090'))); echo "\n剔除address 127.0.0.1:9090 127.0.0.2:9090,放入故障address列表\n"; AddressManager::kickAddress('127.0.0.1:9090'); AddressManager::kickAddress('127.0.0.2:9090'); echo "\n打印故障address列表\n"; var_export(AddressManager::getBadAddressList()); echo "\n获取HelloWorld服务的一个可用address\n"; var_export(AddressManager::getOneAddress('HelloWorld')); echo "\n恢复address 127.0.0.2:9090\n"; var_export(AddressManager::recoverAddress('127.0.0.2:9090')); echo "\n打印故障address列表\n"; var_export(AddressManager::getBadAddressList()); echo "\n配置有更改,md5会改变,则故障address列表自动清空\n"; AddressManager::config(array('HelloWorld' => array('127.0.0.2:9090', '127.0.0.3:9090'))); echo "\n打印故障address列表\n"; var_export(AddressManager::getBadAddressList()); }
<?php $addressManager = new AddressManager($db); try { $address = $addressManager->findByIdUser($currentUser->getId()); } catch (Exception $e) { $address = $e->getMessage(); } $ship_address = $ship_postal_code = $ship_city = $ship_region = $ship_country = $bill_address = $bill_postal_code = $bill_city = $bill_region = $bill_country = ""; if (is_object($address)) { $ship_address = $address->getShipAddress(); $ship_postal_code = $address->getShipPostalCode(); $ship_city = $address->getShipCity(); $ship_region = $address->getShipRegion(); $ship_country = $address->getShipCountry(); $bill_address = $address->getBillAddress(); $bill_postal_code = $address->getBillPostalCode(); $bill_city = $address->getBillCity(); $bill_region = $address->getBillRegion(); $bill_country = $address->getBillCountry(); } require 'views/edit_address.phtml';
<?php require 'fpdf17/fpdf.php'; include 'fpdf17/php-barcode.php'; include_once "./Manager/ConnectionManager.php"; include_once "./Manager/ProductManager.php"; include_once "./Manager/CustomerManager.php"; include_once "./Manager/OrderManager.php"; include_once "./Manager/AddressManager.php"; $productMgr = new ProductManager(); $customerMgr = new CustomerManager(); $orderMgr = new OrderManager(); $addressMgr = new AddressManager(); // -------------------------------------------------- // // GET ORDER INFORMATION // -------------------------------------------------- // $order_id = implode("", $_POST); $orderList = $orderMgr->getPendingOrder(); $order = []; //var_dump($orderList); foreach ($orderList as $o) { if ($o["order_id"] === $order_id) { $order = $o; } } //$order = $orderList[$order_id]; //var_dump($order); class eFPDF extends FPDF { function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle = 0) {
<div class="table-responsive"> <table class="table table-bordered table-hover table-striped" id="displayPendingOrder"> <thead> <tr> <th>Order ID</th> <th>Customer ID</th> <th>Total Price</th> <th>Pay Time</th> <th>Status</th> <th width="10%">Option</th> </tr> </thead> <tbody> <?php $orderMgr = new OrderManager(); $addressMgr = new AddressManager(); $pendingList = $orderMgr->getPendingOrder(); foreach ($pendingList as $pendingOrder) { $pendingOrder_id = $pendingOrder["order_id"]; $pendingOrder_customerId = $pendingOrder["customer_id"]; $pendingOrder_status = $pendingOrder["status"]; $pendingOrder_payTime = $pendingOrder["payment_time"]; $pendingOrder_totalPrice = $pendingOrder["totalPrice"]; $pendingOrder_itemList = $pendingOrder["itemList"]; $pendingOrder_address = $addressMgr->getGeneralAddress($pendingOrder_customerId, intval($pendingOrder['address_no'])); ?> <tr> <td><?php echo $pendingOrder_id; ?> </td>
include_once "./Manager/ConnectionManager.php"; include_once "./Manager/AddressManager.php"; $form_data = array(); $errors = array(); $operation = $_GET['operation']; $customer_id = $_SESSION["userid"]; if ($operation === 'add') { $success = true; $firstname = addslashes(filter_input(INPUT_POST, 'firstname')); $lastname = addslashes(filter_input(INPUT_POST, 'lastname')); $street = addslashes(filter_input(INPUT_POST, 'street')); $blockno = addslashes(filter_input(INPUT_POST, 'blockno')); $floor = addslashes(filter_input(INPUT_POST, 'floor')); $unit = addslashes(filter_input(INPUT_POST, 'unit')); $postalcode = addslashes(filter_input(INPUT_POST, 'postalcode')); $addressMgr = new AddressManager(); if (empty($firstname)) { $success = false; $form_data['status'] = 'fail'; $form_data['message'] = 'You need to specify receiver firstname'; } if (empty($lastname)) { $success = false; $form_data['status'] = 'fail'; $form_data['message'] = 'You need to specify receiver lastname'; } if (empty($street)) { $success = false; $form_data['status'] = 'fail'; $form_data['message'] = 'You need to specify street'; }
$userManager = new UserManager($db); try { $retour = $addressManager->findByIdUser($currentUser->getId()); } catch (Exception $e) { $retour = $e->getMessage(); } if (is_string($retour)) { $retour = $addressManager->create($currentUser, $_POST['ship_address'], $_POST['ship_city'], $_POST['ship_postal_code'], $_POST['ship_region'], $_POST['ship_country'], $_POST['bill_address'], $_POST['bill_city'], $_POST['bill_postal_code'], $_POST['bill_region'], $_POST['bill_country']); if (is_string($retour)) { $errors = array_merge($errors, $retour); } else { header('Location: index.php?page=profil'); exit; } } else { $addressManager = new AddressManager($db); $address = $addressManager->findByIdUser($_SESSION['id']); $address->setShipAddress($_POST['ship_address']); $address->setShipCity($_POST['ship_city']); $address->setShipPostalCode($_POST['ship_postal_code']); $address->setShipRegion($_POST['ship_region']); $address->setShipCountry($_POST['ship_country']); $address->setBillAddress($_POST['bill_address']); $address->setBillCity($_POST['bill_city']); $address->setBillPostalCode($_POST['bill_postal_code']); $address->setBillRegion($_POST['bill_region']); $address->setBillCountry($_POST['bill_country']); $retour = $addressManager->update($address); if (is_array($retour)) { $errors = array_merge($errors, $retour); } else {