Example #1
0
 public function auth($authToken, $login = null, $password = null)
 {
     if (is_null($authToken)) {
         $soapHeader = new \SoapHeader('urn:zimbra', 'context');
         $params = array(ZimbraSoapClient::SoapVarArray(array('account' => $login, 'password' => $password)));
         $result = $this->__soapCall("AuthRequest", $params, null, $soapHeader);
         if (array_key_exists('authToken', $result)) {
             $this->authToken = $result['authToken'];
             return $this->authToken;
         } else {
             return false;
         }
     } else {
         $params = array(ZimbraSoapClient::SoapVarArray(array('authToken' => array('@verifyAccount' => 1, '%' => $authToken))));
         try {
             $result = $this->__soapCall("AuthRequest", $params, null, $soapHeader);
             $this->authToken = $result['authToken'];
             return $this->authToken;
         } catch (SoapFault $e) {
             if ($e->getMessage() == 'no valid authtoken present') {
                 return $this->auth(null, $login, $password);
             }
             throwException($e);
         }
     }
 }
Example #2
0
 /**
  * 运行应用程序
  * @param string $do 动作名称
  * @param string $mo 模块名称
  * @return AdminCP
  */
 function run($do = NULL, $moduleClass = NULL)
 {
     $do === NULL && ($do = $this->action);
     $moduleClass === NULL && ($moduleClass = $this->module);
     //$mo == 'Logout' && Admin::logout(__SELF__);
     $moduleFile = iPATH . 'admin/' . $moduleClass . '.mo.php';
     if (is_file($moduleFile) || empty($mo)) {
         if (!class_exists($moduleClass)) {
             if (is_file($moduleFile)) {
                 include_once $moduleFile;
             } else {
                 $moduleClass = 'iAction';
             }
         }
         if (class_exists($moduleClass)) {
             $module = new $moduleClass($this);
             $method = 'do' . $do;
             //                $method = $do?'do'.$do:($ac?'action'.$ac:'');
             if (method_exists($module, $method)) {
                 if ($this->param === NULL) {
                     $module->{$method}();
                 } else {
                     $module->{$method}($this->param);
                 }
             } else {
                 throwException('应用程序运行出错.类 ' . $moduleClass . ' 中找不到方法定义:' . $method, 1003);
             }
         } else {
             throwException('应用程序运行出错.文件 ' . $moduleFile . ' 中找不到类定义:' . $moduleClass, 1002);
         }
     } else {
         throwException('应用程序运行出错.找不到文件:' . $moduleFile, 1001);
     }
     return $this;
 }
 public function testMapExceptionHandling()
 {
     $maybeInt = Maybe::fromValue(1);
     $maybeIntPlusOne = $maybeInt->map(function ($i) {
         return throwException($i);
     });
     $this->assertInstanceOf('TMciver\\Functional\\Maybe\\Nothing', $maybeIntPlusOne);
 }
Example #4
0
 public function getPrice()
 {
     $price = $this->price()->get()->first();
     if (!isset($price)) {
         throwException('Price not set');
     }
     return $price;
 }
Example #5
0
 public function setContent($value)
 {
     if ($value === null || is_string($value)) {
         $this->object->Content = $value;
         return $this;
     }
     throwException(new \Exception("Parameter value must be of type 'string'"));
 }
 /**
  * 
  * @param string $format, the response type
  * @return \api\models\ResponseFormatter
  * 
  */
 public static function getFormatter($format = Response::FORMAT_JSON)
 {
     $class = __NAMESPACE__ . "\\ResponseFormatter" . strtoupper($format);
     if (class_exists($class)) {
         return new $class();
     } else {
         throwException(new \Exception("Could not find Response formatter for {$format}", null, null));
     }
 }
 public function send($to, $message)
 {
     $result = null;
     $message = Config::get('sms.prefix') . $message . Config::get('sms.suffix');
     if (false == SenderFactory::validate($to)) {
         throwException(new InvalidMobileNumberException("非法的手机号码:{$to}"));
     } else {
         $result = $this->doSend($to, $message);
         $this->log->info("发送短信", array('to' => $to, 'message' => $message, 'result' => $result));
     }
     return $result;
 }
Example #8
0
 /**
  * @param array $args
  * @return Uploader
  */
 public static function create(array $args)
 {
     if (count($args) < 3) {
         throwException(new \Exception('Not enough arguments'));
     }
     if ($args[0] === 'image' && count($args) == 4) {
         return new ImageUploader($args[1], $args[2], $args[3]);
     }
     if ($args[0] === 'file' && count($args) == 4) {
         return new FileUploader($args[1], $args[2], $args[3]);
     }
 }
 /**
  * Store a newly created theme in database.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $filePath = $this->handleImageUpload($request->file('theme_zip_file'));
     $zip = new \ZipArchive();
     if ($zip->open($filePath) === true) {
         $extractPath = base_path('themes');
         $zip->extractTo($extractPath);
         $zip->close();
     } else {
         throwException('Error in Zip Extract error.');
     }
     return redirect()->route('admin.theme.index');
 }
 /**
  * 获取全局对象
  * @param $path
  * @param $className
  */
 public static function getGlobal($path, $className = null)
 {
     if (!is_object(self::$_global[$path])) {
         import($path);
         if (is_null($className)) {
             throwException('实例化对象名称不能为空 path : ' . $path);
         }
         if (!class_exists($className)) {
             throwException('对象不存在 : ' . $className);
         }
         self::$_global[$path] = new $className();
     }
     return self::$_global[$path];
 }
Example #11
0
 public function isConnected()
 {
     try {
         $this->ftp->systype();
     } catch (\FtpException $e) {
         if ($e->getMessage() == "Not connected to FTP server. Call connect() or ssl_connect() first.") {
             return false;
         } else {
             // @codeCoverageIgnoreStart
             throwException($e);
             // @codeCoverageIgnoreEnd
         }
     }
     return true;
 }
Example #12
0
 /**
  * 设置缓存参数
  * @param array $options 要设置的缓存参数
  */
 protected function setOption($name, $value)
 {
     if (!is_string($name)) {
         throwException("不正确的参数名称 : {$name}");
     }
     $name = strtolower($name);
     if (array_key_exists($name, $this->getOption())) {
         $this->_options[$name] = $value;
     }
     if ($this->_options['cache_dir'] === null) {
         $this->setOption('cache_dir', $this->getTmpDir() . DIRECTORY_SEPARATOR);
     }
     if ($this->_options['page_dir'] === null) {
         $this->setOption('page_dir', $this->getTmpDir() . DIRECTORY_SEPARATOR);
     }
 }
Example #13
0
 /**
  * 获取cache实例
  *
  * @param string $conf 使用的缓存配置;
  *
  * @return \Foundation\Cache\Redis | \Foundation\Cache\Apc | \Foundation\Cache\File | \Foundation\Cache\Memcache
  */
 public function cache($conf = 'default_cache')
 {
     $config = is_array($conf) ? $conf : Config::get($conf);
     $driver = '\\Foundation\\Cache\\' . $config['driver'];
     if (isset(self::$cacheInstance[$conf])) {
         return self::$cacheInstance[$conf];
     } else {
         if ($config['on']) {
             self::$cacheInstance[$conf] = new $driver($config);
             return self::$cacheInstance[$conf];
         } else {
             throwException(Lang::get('_NOT_OPEN_', $conf));
             return false;
         }
     }
 }
Example #14
0
 function edit_campain($id)
 {
     try {
         $campaign = $this->mailChimp->campaigns->getList(array('campaign_id' => $id));
         if ($campaign['total'] == 0) {
             throwException(lang('Campain not found', 'mail_chimp'));
         }
         $data = $this->mailChimp->campaigns->content($id);
         $model['html'] = preg_replace('/<center>(.|\\n)*<\\/center>/', '', $data['html']);
         $model = array_merge($model, $campaign);
         $lists = $this->mailChimp->lists->getList();
         \CMSFactory\assetManager::create()->setData('model', $model)->setData('lists', $lists)->renderAdmin('edit');
     } catch (Exception $exc) {
         showMessage($exc->getMessage(), FALSE, 'r');
         pjax('/admin/components/init_window/mail_chimp');
     }
 }
Example #15
0
 /**
  * 获取Lock实例
  *
  * @param string|null $useCache 使用的锁的配置
  *
  * @return \Foundation\Lock\Redis | \Foundation\Lock\Memcache | \Foundation\Lock\File | false
  * @throws \Exception
  */
 public function locker($useCache = null)
 {
     is_null($useCache) && ($useCache = Config::get('locker_use_cache', 'default_cache'));
     static $_instance = array();
     $config = Config::get($useCache);
     if (isset($_instance[$useCache])) {
         return $_instance[$useCache];
     } else {
         if ($config['on']) {
             $lock = 'Foundation\\Lock\\' . $config['driver'];
             $_instance[$useCache] = new $lock($useCache);
             return $_instance[$useCache];
         } else {
             throwException(Lang::get('_NOT_OPEN_', $useCache));
             return false;
         }
     }
 }
Example #16
0
 public function deleteGroup($gid, Request $request)
 {
     //if logged process otherwise go to login form
     $current_user = ParseUser::getCurrentUser();
     if (!$current_user) {
         return redirect()->route('login');
     }
     $query = new ParseQuery("Groups");
     try {
         $group = $query->get($gid);
         $owner = $group->get('user')->fetch();
         if ($current_user->getObjectId() != $owner->getObjectId() && $group->get('public') !== true) {
             throwException(401, "Sorry you don't have access to delete this group.");
         } else {
             $group->destroy();
             return redirect('/groups');
         }
     } catch (ParseException $ex) {
         // The object was not retrieved successfully.
         // error is a ParseException with an error code and message.
         echo $ex->getMessage();
     }
 }
Example #17
0
 public function deleteEvent($id, Request $request)
 {
     $current_user = ParseUser::getCurrentUser();
     if (!$current_user) {
         return redirect()->route('login');
     }
     $query = new ParseQuery("Events");
     $query->includeKey('user');
     try {
         $event = $query->get($id);
         $owner = $event->get('user');
         if ($current_user->getObjectId() != $owner->getObjectId()) {
             throwException(401, "Sorry you don't have access to delete this event.");
         } else {
             $event->destroy();
             return redirect('/groups');
         }
     } catch (ParseException $ex) {
         // The object was not retrieved successfully.
         // error is a ParseException with an error code and message.
         echo $ex->getMessage();
     }
 }
Example #18
0
 /**
  * 数据库操作执行错误
  * @param string $sql 错误的SQL语句
  * @access private
  */
 function error($sql)
 {
     throwException('SQL执行错误: <b>' . $sql . '</b><br /> 错误代码: <b>' . mysql_errno($this->connect) . '</b><br /> 错误信息: <b>' . mysql_error($this->connect) . '</b>', 4001);
 }
 /**
  * Show the application registration form.
  *
  * @return \Illuminate\Http\Response
  */
 public function getRegister()
 {
     throwException("can't register directly for admin accounts");
     //return view('mage2::admin.auth.register');
 }
function gen()
{
    (yield 'foo');
    strlen("foo", "bar", throwException());
    (yield 'bar');
}
Example #21
0
 /**
  * 加入排序
  * @param string $fieldName 字段名
  * @param string $orderBy 排序方式
  * @return OrmQuery
  */
 function addOrderBy($fieldName, $orderBy = _ORM_OP_ASC)
 {
     $fieldName = trim($fieldName);
     if (empty($fieldName)) {
         throwException('排序字段名不能为空', 4052);
     }
     $this->sql['order'][] = array('name' => $fieldName, 'order' => $orderBy);
     return $this;
 }
 public static function getUrlParams()
 {
     loadCore('registry/RegistryRequest');
     self::$_registryRequest = RegistryRequest::getInstance();
     switch (config('URL_MODEL')) {
         case URL_COMMON:
             //默认模式
             self::_common();
             break;
         case URL_PATHINFO:
             //pathinfo模式
             break;
         case URL_REWRITE:
             //伪静态模式
             break;
         case URL_COMPAT:
             //兼容模式
             break;
         default:
             throwException('事件分发错误,请检测URL配置');
             break;
     }
 }
Example #23
0
 /**
  * 启动框架
  *
  */
 public static function runApp()
 {
     //系统初始化
     self::init();
     //控制器所在路径
     $actionController = APP_CONTROLLER_PATH . Route::$urlParams['controller'] . 'Controller.php';
     $GLOBALS['debug'] && Debug::addTipInfo(Lang::get('_ACTION_CONTROLLER_', $actionController));
     Plugin::hook('alpha.before_run_controller');
     if (is_file($actionController)) {
         $className = Route::$urlParams['controller'] . 'Controller';
         $className = (IS_MULTI_MODULES ? '' : '\\Controller') . Route::$urlParams['path'] . (IS_MULTI_MODULES ? 'Controller' . DIRECTORY_SEPARATOR : '') . "{$className}";
         $className = str_replace('/', '\\', $className);
         $controller = new $className();
         call_user_func(array($controller, "runAppController"));
         //运行
     } else {
         self::montFor404Page();
         if ($GLOBALS['debug']) {
             throwException(Lang::get('_CONTROLLER_NOT_FOUND_', APP_CONTROLLER_PATH, Route::$urlParams['controller'], str_replace('/', '\\', Route::$urlParams['path']) . Route::$urlParams['controller']));
         } else {
             Response::show404Page();
         }
     }
     //输出Debug模式的信息
     self::Stop();
 }
Example #24
0
 /**
  * 防止csrf跨站攻击
  *
  * @param int $type 检测类型   0不检查,1、只检查post,2、post get都检查
  */
 public static function checkCsrf($type = 1)
 {
     if ($type !== 0 && isset($_SERVER['HTTP_REFERER']) && !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) {
         if ($type == 1) {
             if (!empty($_POST)) {
                 Response::sendHttpStatus(403);
                 throwException(Lang::get('_ILLEGAL_REQUEST_'));
             }
         } else {
             Response::sendHttpStatus(403);
             throwException(Lang::get('_ILLEGAL_REQUEST_'));
         }
     }
 }
Example #25
0
 /**
  * 匹配路由
  *
  * @param string $pathinfo
  *
  * @return mixed
  */
 private static function isRoute(&$pathinfo)
 {
     empty($pathinfo) && ($pathinfo[0] = '/');
     //网站根地址
     $issuccess = array();
     $route = self::$rules;
     switch ($_SERVER['REQUEST_METHOD']) {
         case 'GET':
             $rmethod = self::REQUEST_METHOD_GET;
             break;
         case 'POST':
             $rmethod = self::REQUEST_METHOD_POST;
             break;
         case 'PUT':
             $rmethod = self::REQUEST_METHOD_PUT;
             break;
         case 'PATCH':
             $rmethod = self::REQUEST_METHOD_PATCH;
             break;
         case 'DELETE':
             $rmethod = self::REQUEST_METHOD_DELETE;
             break;
         case 'OPTIONS':
             $rmethod = self::REQUEST_METHOD_OPTIONS;
             break;
         default:
             $rmethod = self::REQUEST_METHOD_ANY;
     }
     foreach ($route as $k => $v) {
         $rulesmethod = substr($k, 0, 1);
         if ($rulesmethod != $rmethod && $rulesmethod != self::REQUEST_METHOD_ANY && $rulesmethod != self::RESTROUTE) {
             //此条路由不符合当前请求方式
             continue;
         }
         unset($v);
         $singleRule = substr($k, 1);
         $arr = $singleRule === '/' ? array(0 => $singleRule) : explode('/', ltrim($singleRule, '/'));
         if ($arr[0] == $pathinfo[0]) {
             array_shift($arr);
             foreach ($arr as $key => $val) {
                 if (isset($pathinfo[$key + 1]) && $pathinfo[$key + 1] !== '') {
                     if (strpos($val, '\\d') && !is_numeric($pathinfo[$key + 1])) {
                         //数字变量
                         $route[$k] = false;
                         //匹配失败
                         break 1;
                     } elseif (strpos($val, ':') === false && $val != $pathinfo[$key + 1]) {
                         //字符串
                         $route[$k] = false;
                         //匹配失败
                         break 1;
                     }
                 } else {
                     $route[$k] = false;
                     //匹配失败
                     break 1;
                 }
             }
         } else {
             $route[$k] = false;
             //匹配失败
         }
         if ($route[$k] !== false) {
             //匹配成功的路由
             $issuccess[] = $k;
         }
     }
     if (empty($issuccess)) {
         $returnArr[0] = false;
     } else {
         //匹配到多条路由时 选择最长的一条(匹配更精确)
         usort($issuccess, function ($item1, $item2) {
             return strlen($item1) >= strlen($item2) ? 0 : 1;
         });
         if (is_callable($route[$issuccess[0]])) {
             call_user_func($route[$issuccess[0]]);
             Alpha::Stop();
         }
         $route[$issuccess[0]] = trim($route[$issuccess[0]], '/');
         //判断路由的正确性
         count(explode('/', $route[$issuccess[0]])) >= 2 || throwException(Lang::get('_ROUTE_PARAM_ERROR_', substr($issuccess[0], 1)));
         $returnArr[0] = true;
         $successRoute = explode('/', $issuccess[0]);
         foreach ($successRoute as $key => $val) {
             $t = explode('\\d', $val);
             if (strpos($t[0], ':') !== false) {
                 $_GET[ltrim($t[0], ':')] = $pathinfo[$key];
             }
             unset($pathinfo[$key]);
         }
         if (substr($issuccess[0], 0, 1) == self::RESTROUTE) {
             $actions = explode('/', $route[$issuccess[0]]);
             $arrKey = count($actions) - 1;
             $actions[$arrKey] = strtolower($_SERVER['REQUEST_METHOD']) . ucfirst($actions[$arrKey]);
             $route[$issuccess[0]] = implode('/', $actions);
         }
         $returnArr['route'] = $route[$issuccess[0]];
     }
     return $returnArr;
 }
/**
 * 复写file_put_contents
 * @param $filename
 * @param $data
 * @param $flags
 * @param $context
 */
function writeData($filename, $data, $flags = null, $context = null)
{
    if (file_put_contents($filename, $data, $flags, $context)) {
        return true;
    } else {
        throwException("文件写入失败,path:{$filename}.内容:{$context}");
    }
}
 private function _query($sql)
 {
     Trace::addLog($sql);
     $result = mysql_query($sql, $this->_link) or throwException("error sql: {$sql}. \t " . mysql_error($this->_link));
     return $result;
 }
 public function Execute($payKey = null)
 {
     if ($payKey == null && $this->getPayKey()) {
         throwException("PayKey Missing");
         $this->log->addError("Execute Payment Error No Pay Key");
     }
     $executePaymentRequest = new \ExecutePaymentRequest(new \RequestEnvelope("en_US"), $payKey);
     $executePaymentRequest->actionType = "PAY";
     $this->serviceRequest = new AdaptivePaymentsService($this->config);
     $response = $this->serviceRequest->ExecutePayment($executePaymentRequest);
     $this->log->addInfo("Execute Payment Response", array($response));
     return $this->handleResponse($response) ? true : false;
 }
 /**
  * 出错处理方式
  */
 function error($function, $errormsg)
 {
     throwException('Error in file <b>' . __FILE__ . '</b> ,Function <b>' . $function . '()</b> :' . $errormsg);
 }
Example #30
0
             eval('return $e"bc";');
             break;
         case 'class':
             $odysseus = new NoMan();
             break;
     }
     break;
 case 'respondWithException':
     set_exception_handler('ResponseUtil::respondWithException');
     switch ($subcase) {
         case 'normal':
             throw new Exception("I'm dyin' here.");
             break;
         case 'long':
             ResponseUtil::$longErrorTrace = true;
             throwException();
             break;
     }
     break;
 case 'catchDouble':
     set_exception_handler('ResponseUtil::respondWithException');
     $response = new ResponseUtil();
     $response = new ResponseUtil();
     break;
 case 'sendHttp':
     $r = new ResponseUtil();
     if (ctype_digit($subcase) || is_int($subcase)) {
         $r->sendHttp($subcase);
     }
     $r['message'] = 'The response';
     $r['error'] = false;