コード例 #1
0
ファイル: Base.php プロジェクト: 645248882/CocoPHP
 /**
  * 检测钻石余额
  *
  * @param int $amount 数量
  * @return void
  */
 public function checkDiamond($amount)
 {
     if ($amount > $this->_user['diamond']) {
         throws('NoEnoughDiamond');
     }
     return true;
 }
コード例 #2
0
ファイル: Auth.php プロジェクト: 645248882/CocoPHP
 public static function getUidByDevice($imei, $platform)
 {
     if (!$imei || !$platform) {
         throws("Device register error", 1002);
     }
     $token = md5($imei . '-' . $platform);
     // 根据token获取用户信息
     if (!($uid = Dao('UserDevice')->getUidByDevice($token))) {
         $setArr = array('imei' => $imei, 'platform' => $platform, 'token' => $token);
         return Dao('UserDevice')->insert($setArr);
     }
     return $uid;
 }
コード例 #3
0
ファイル: Abstract.php プロジェクト: 645248882/CocoPHP
 public function init()
 {
     return true;
     $request = $this->getQueryx();
     if (0 && !$this->_validate($request)) {
         throws("登陆参数验证不通过");
     }
     //$uid = Model_User_Api_Auth::getUidByDevice($request['imei'], $request['platform']);
     $uid = 1;
     if (!$uid) {
         throws("登陆失败", 1001);
     }
     $this->_user = new Model_User($uid);
     $this->_uid = $this->_user['uid'];
 }
コード例 #4
0
ファイル: Db.php プロジェクト: 645248882/CocoPHP
 /**
  * 取得DB连接
  *
  * @param string $dbName
  * @return void
  */
 public static function get($dbName)
 {
     // 获取数据库连接配置
     $dbConf = Core_Config::load('Db');
     if (!$dbConf || !is_array($dbConf)) {
         throws("Empty DB CONFIG  please check db.conf.php file", 'sql');
     }
     $dbServer = $dbConf[$dbName];
     if (!$dbServer) {
         throws('Invalid DB configuration [' . $dbName . '], plz check: db.conf.php', 'sql');
     }
     if (!isset(self::$_dbs[$dbName])) {
         // 创建数据库连接实例
         self::$_dbs[$dbName] = new Com_Db_Pdo($dbServer, $dbConf['persistent'], $dbConf['emulate_prepare']);
     }
     return self::$_dbs[$dbName];
 }
コード例 #5
0
ファイル: article.php プロジェクト: davidmancini/cnn
 public function insert(PDO $pdo)
 {
     //Only inserts if new id
     if ($this->articleId !== null) {
         throws(new PDOException("not a new article id"));
     }
     //creates query
     $query = "INSERT INTO article(authorId, title, description, copy) VALUES(:authorId, :title, :description, :copy)";
     $statement = $pdo->prepare($query);
     //binds variables to placeholders
     $parameters = array("authorId" => $this->authorId, "title" => $this->title, "description" => $this->description, "copy" => $this->copy);
     $statement->execute($parameters);
     //updates null article id with the newly generated id number from database
     $this->articleId = intval($pdo->lastInsertId());
 }
コード例 #6
0
ファイル: unit_test.php プロジェクト: Archieru/dbackend
test('Cached value should exist');
asrt(apc_exists("configList"), "configList does not exist");
test('Should set cached value');
$list = apc_fetch("configList");
$passed = in_array('register', $list) && in_array('login', $list);
asrt($passed, http_build_query($list));
$writeconfig = file('register.example');
$readconfig = file('login.example');
require_once 'functions_main.inc';
testSuite('Read config test');
test('Should throw error on empty parameters');
readConfig(false);
throws("no action provided");
test('Should throw error on nonexistent action');
readConfig('some_weird_action');
throws("unrecognized action");
test('Action exists, but no file for it');
readConfig('login');
throws("unable to find config for this action");
test('Action exists, but no file for it');
$passed = readConfig('login', '.example');
asrt(startsWith($passed[0], 'IMPORT'), $passed[0]);
testSuite('Test import');
test('Should throw error on empty parameters');
$toParse[0] = 'IMPORT login.example';
$toParse[1] = 'DBCONFIG best : mana';
$parsed = doIMPORT($toParse);
$dbConfig = getDbConfigs($parsed);
$passed = $dbConfig['best'] == 'mana' && $dbConfig['user'] == 'loginreader';
asrt($passed, http_build_query($dbConfig));
finish();
コード例 #7
0
ファイル: Dao.php プロジェクト: 645248882/CocoPHP
 public function __call($method, $args)
 {
     // SQL查询链式操作
     $selectMethods = array('table' => 1, 'field' => 1, 'where' => 1, 'order' => 1, 'join' => 1, 'limit' => 1, 'group' => 1, 'lock' => 1, 'having' => 1);
     if (isset($selectMethods[$method])) {
         $this->_options[$method] = isset($args[0]) ? $args[0] : null;
         return $this;
     }
     // 写操作
     $writeMethods = array('insert' => 1, 'update' => 1, 'delete' => 1, 'increment' => 1, 'decrement' => 1);
     // 读操作
     $readMethods = array('fetchAll' => 1, 'fetchAssoc' => 1, 'fetchOne' => 1, 'fetchRow' => 1, 'fetchCol' => 1, 'fetchPairs' => 1);
     if (isset($readMethods[$method])) {
         return $this->_read($method);
     }
     // 执行写操作
     if (isset($writeMethods[$method])) {
         if ($method == 'delete' && $args) {
             throws('Com_Dao::delete() 的条件参数必须使用 where() 等方法来设置', 'sql');
         } elseif ($method == 'update' && count($args) > 1) {
             throws('Com_Dao::update() 的条件参数必须使用 where() 等方法来设置', 'sql');
         }
         return $this->_write($method, $args);
     }
     throws('Call to undefined method Com_Dao::' . $method, 'sql');
 }
コード例 #8
0
namespace Buttercup\Protects\Tests;

use Buttercup\Protects\DomainEvent;
use Buttercup\Protects\DomainEvents;
use Buttercup\Protects\RecordsEvents;
use Buttercup\Protects\Tests\Misc\ProductId;
use Exception;
// As an example, let's introduce an invariant that states that *"A Basket can have no more than three Products"*.
// Let's write a test that proves that the a `BasketLimitReached` exception is thrown when we try to violate the invariant.
$test = function () {
    $basket = BasketV2::pickUp(BasketId::generate());
    $basket->addProduct(new ProductId('TPB1'), "The Princess Bride");
    $basket->addProduct(new ProductId('TPB2'), "The book");
    $basket->addProduct(new ProductId('TPB3'), "The DVD");
    it("should disallow adding a fourth product", throws('Buttercup\\Protects\\Tests\\BasketLimitReached', function () use($basket) {
        $basket->addProduct(new ProductId('TPB4'), "The video game");
    }));
};
// (The V2 is just to prevent naming collisions, and can be ignored.)
final class BasketV2 implements RecordsEvents
{
    private $productCount;
    public static function pickUp(BasketId $basketId)
    {
        $basket = new BasketV2($basketId);
        $basket->recordThat(new BasketWasPickedUp($basketId));
        // A new basket doesn't have any products yet. It's good to set the initial state explicitly here.
        $basket->productCount = 0;
        return $basket;
    }
    public function addProduct(ProductId $productId, $name)