コード例 #1
0
ファイル: Cricket.php プロジェクト: neerav-mehta/yboocs
<?php

PubSub::subscribe('Cricket', function () {
    $moduleName = 'Cricket';
    $params = func_get_args();
    $callBackMethod = $params[0];
    array_shift($params);
    echo $callBackMethod;
    call_user_func_array(array(__NAMESPACE__ . '\\Cricket', $callBackMethod), $params);
});
class Cricket
{
    public static $cricInfoURL = 'http://cricscore-api.appspot.com/csa';
    public static $homeCountry = 'India';
    public static $askForLiveScoreString = 'Between which two team you want to get the live match score information?(team1,team2)';
    public static $CRICKET_OPTION_MESSAGE = "Do you want to get score of any other match\n        1 for Yes\n        2 for No";
    public static function initializeService($requester)
    {
        $matchList = file_get_contents(self::$cricInfoURL);
        $scoreAvailable = false;
        if ($matchList) {
            $json = json_decode($matchList, true);
            foreach ($json as $value) {
                echo $value['t1'] . '/n';
                echo $value['t2'] . '/n/n';
                if (stripos($value['t1'], self::$homeCountry) > -1 || stripos($value['t2'], self::$homeCountry) > -1) {
                    $matchScoreURL = self::$cricInfoURL . '?id=' . $value['id'];
                    $matchScore = file_get_contents($matchScoreURL);
                    $matchScore = json_decode($matchScore, true);
                    $score = $matchScore['0']['de'];
                    MessaggingController::sendMessage($requester, $score);
コード例 #2
0
ファイル: aaa.php プロジェクト: neerav-mehta/yboocs
        if (count(self::$events[$name]) === 1) {
            if (is_callable(self::$events[$name][0])) {
                return call_user_func_array(self::$events[$name][0], $params);
            } else {
                return false;
            }
        }
        // Loop through all the events and call them
        foreach (self::$events[$name] as $event) {
            if (is_callable($event)) {
                call_user_func_array($event, $params);
            }
        }
    }
    public static function unsubscribe($name)
    {
        if (!empty(self::$events[$name])) {
            unset(self::$events[$name]);
        }
    }
}
// Basic usage
PubSub::subscribe('beforeSave', function ($helo) {
    echo $helo;
    echo 'PubSub::beforeSave';
});
PubSub::subscribe('afterSave', function () {
    echo 'PubSub::afterSave';
});
PubSub::publish('beforeSave', "Helo");
PubSub::unsubscribe('beforeSave');
コード例 #3
0
<?php

include_once '../dbManager.php';
include_once '../ServiceController.php';
PubSub::subscribe('UserManagement', function () {
    $moduleName = 'UserManagement';
    $params = func_get_args();
    $callBackMethod = $params[0];
    array_shift($params);
    call_user_func_array(array(__NAMESPACE__ . '\\UserManagement', $callBackMethod), $params);
});
class UserManagement
{
    public static function initializeService($receiver, $response)
    {
        $replyMsg = "Hi " . $receiver['nickname'] . GenieConstants::$WELCOME_MESSAGE;
        MessaggingController::sendMessage($receiver, $replyMsg);
        self::askForGenderInformation($receiver, $response);
        $menu_Context = GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, GenieConstants::$REGISTRATION_MENU_CONTEXT, 'subMenu');
        $subMenu_Context = GenieConstants::searchElement(GenieConstants::$REGISTRATION_MENU_CONTEXT, GenieConstants::$GENDER_SUB_MENU_STRING, 'menuItem');
        updateMessageContext($menu_Context, $subMenu_Context, $receiver['phone']);
    }
    public static function processGenderInformation($receiver, $response)
    {
        $regex = GenieConstants::$genderRegex;
        if (preg_match($regex, $response) == 0) {
            $errorMessage = GenieConstants::$ERROR_MESSAGE;
            MessaggingController::sendMessage($receiver, $errorMessage);
            self::askForGenderInformation($receiver, $response);
            return;
        } else {
コード例 #4
0
            return $key;
        }
    }
    return -1;
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
// Basic usage
PubSub::subscribe('message_received', function () {
    $params = func_get_args();
    call_user_func_array(__NAMESPACE__ . '\\ServiceController::handleMessageReceived', $params);
});
PubSub::subscribe('SERVICE_REQUEST_COMPLETE', function () {
    $params = func_get_args();
    call_user_func_array(array(__NAMESPACE__ . '\\ServiceController', 'handleServiceRequestComplete'), $params);
});
class ServiceController
{
    static function handleServiceRequestComplete($requester)
    {
        $context = getMessageContext($requester['phone']);
        if ($context['main_menu'] != 0 && $context['sub_menu'] != NULL) {
            $SubMenuDict = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu;
            $postServiceMessage = $SubMenuDict[$context['sub_menu']]->postServiceMessage;
            echo "\n\n\n";
            var_dump($SubMenuDict);
            var_dump($context);
            MessaggingController::sendMessage($requester, $postServiceMessage);
            $anythingElse = GenieConstants::$anyThingElse;
            MessaggingController::sendMessage($requester, $anythingElse);
コード例 #5
0
ファイル: PubSubTest.php プロジェクト: abcarroll/DABL
 /**
  * @covers PubSub::unsubscribe
  */
 public function testRemove()
 {
     $callbacks = array(function () {
         PubSubTest::$callbackCalled = true;
     }, array('PubSubTest', 'staticCallback'), array($this, 'instanceCallback'), 'global_pub_sub_test_callback');
     foreach ($callbacks as $key => $callback) {
         PubSub::subscribe('my_event', $callback);
         $this->assertEquals(1, count(PubSub::subscriptions('my_event')), '1 callback was added, so 1 callback should be in array.');
         PubSub::unsubscribe('my_event', $callback);
         $this->assertEquals(0, count(PubSub::subscriptions('my_event')), '1 callback was unsubscribed, so 0 callbacks should be in array.');
     }
 }