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


PHP Exception::i方法代码示例

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


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

示例1: getContent

 /**
  * Returns the contents of a file given the path
  *
  * @return string
  */
 public function getContent()
 {
     $this->absolute();
     //if the pat is not a real file
     if (!is_file($this->data)) {
         //throw an exception
         Exception::i()->setMessage(self::ERROR_PATH_IS_NOT_FILE)->addVariable($this->data)->trigger();
     }
     return file_get_contents($this->data);
 }
开发者ID:Eden-PHP,项目名称:File,代码行数:15,代码来源:Index.php

示例2: create

 /**
  * Creates a folder given the path
  *
  * @param int chmod
  *
  * @return this
  */
 public function create($chmod = 0755)
 {
     //argument 1 must be an integer
     Argument::i()->test(1, 'int');
     //if chmod is not and integer or not between 0 and 777
     if (!is_int($chmod) || $chmod < 0 || $chmod > 777) {
         //throw an error
         Exception::i(self::ERROR_CHMOD_IS_INVALID)->addVariable($this->data)->trigger();
     }
     //if it's not a directory
     if (!is_dir($this->data)) {
         //then make it
         mkdir($this->data, $chmod, true);
     }
     return $this;
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:23,代码来源:Folder.php

示例3: import

 /**
  * Main route method
  *
  * @return function
  */
 public function import($escape = '1234567890')
 {
     //remember this scope
     $self = $this;
     $message = self::FAIL_400;
     eve()->addMethod('addCsrf', function (Registry $request, Registry $response, array $meta) use($self, $message) {
         //we already checked the csrf it's good
         //we just need to check if it's set
         //testing GET
         if (isset($meta['check_csrf']) && $meta['check_csrf'] && $meta['method'] === 'GET' && !$request->isKey('get', 'csrf')) {
             Exception::i($message)->trigger();
         }
         //testing POST
         if (isset($meta['check_csrf']) && $meta['check_csrf'] && $meta['method'] === 'POST' && !$meta->isKey('post', 'csrf')) {
             Exception::i($message)->trigger();
         }
         //this is for ALL
         if (isset($meta['check_csrf']) && $meta['check_csrf'] && $meta['method'] === 'ALL' && !empty($_POST) && !$request->isKey('post', 'csrf')) {
             Exception::i($message)->trigger();
         }
         //set csrf
         if (isset($meta['make_csrf']) && $meta['make_csrf']) {
             $request->set('csrf', md5(uniqid()));
         } else {
             if (isset($meta['copy_csrf']) && $meta['copy_csrf']) {
                 $request->set('csrf', $_SESSION['csrf']);
             }
         }
     });
     //You can add validators here
     return function (Registry $request, Registry $response) use($self, $escape, $message) {
         //CSRF - whether or not we are expecting it lets do a check
         $csrf = false;
         if ($request->isKey('get', 'csrf')) {
             $csrf = $request->get('get', 'csrf');
         } else {
             if ($request->isKey('post', 'csrf')) {
                 $csrf = $request->get('post', 'csrf');
             }
         }
         if ($csrf !== false && $csrf !== $_SESSION['csrf'] && $csrf !== $escape) {
             Exception::i($message)->trigger();
         }
     };
 }
开发者ID:eve-php,项目名称:eve-plugin-csrf,代码行数:50,代码来源:Setup.php

示例4: absolute

 /**
  * Attempts to get the full absolute path
  * as described on the server. The path
  * given must exist.
  *
  * @param string|null $root The root path
  *
  * @return Eden\Path\Index
  */
 public function absolute($root = null)
 {
     //argument 1 must be a string or null
     Argument::i()->test(1, 'string', 'null');
     //if path is a directory or file
     if (is_dir($this->data) || is_file($this->data)) {
         return $this;
     }
     //if root is null
     if (is_null($root)) {
         //assume the root is doc root
         $root = $_SERVER['DOCUMENT_ROOT'];
     }
     //get the absolute path
     $absolute = $this->format($this->format($root) . $this->data);
     //if absolute is a directory or file
     if (is_dir($absolute) || is_file($absolute)) {
         $this->data = $absolute;
         return $this;
     }
     //if we are here then it means that no path was found so we should throw an exception
     Exception::i()->setMessage(self::ERROR_FULL_PATH_NOT_FOUND)->addVariable($this->data)->addVariable($absolute)->trigger();
 }
开发者ID:Eden-PHP,项目名称:Path,代码行数:32,代码来源:Index.php

示例5: checkEval

 /**
  * Returns a very nice error message
  *
  * @param *string $code
  *
  * @return Eden\Handlebars\Index
  */
 protected function checkEval($code)
 {
     $error = error_get_last();
     if (isset($error['message']) && isset($error['line']) && $error['message'] === 'parse error') {
         $code = explode("\n", $code);
         $start = $error['line'] - 25;
         if ($start < 0) {
             $start = 0;
         }
         $code = array_splice($code, $start, 50);
         foreach ($code as $i => $line) {
             $code[$i] = ++$start . ': ' . $line;
         }
         Exception::i(self::COMPILE_ERROR)->setType('COMPILE')->addVariable($error['message'])->addVariable($error['line'])->addVariable(implode("\n", $code))->trigger();
     }
     return $this;
 }
开发者ID:Eden-PHP,项目名称:Handlebars,代码行数:24,代码来源:Index.php

示例6: send

 /**
  * Sends an email
  *
  * @param array  $headers Custom headers
  *
  * @return array headers
  */
 public function send(array $headers = array())
 {
     //if no socket
     if (!$this->socket) {
         //then connect
         $this->connect();
     }
     $headers = $this->getHeaders($headers);
     $body = $this->getBody();
     //add from
     if (!$this->call('MAIL FROM:<' . $this->username . '>', 250, 251)) {
         $this->disconnect();
         //throw exception
         Exception::i()->setMessage(Exception::SMTP_ADD_EMAIL)->addVariable($this->username)->trigger();
     }
     //add to
     foreach ($this->to as $email => $name) {
         if (!$this->call('RCPT TO:<' . $email . '>', 250, 251)) {
             $this->disconnect();
             //throw exception
             Exception::i()->setMessage(Exception::SMTP_ADD_EMAIL)->addVariable($email)->trigger();
         }
     }
     //add cc
     foreach ($this->cc as $email => $name) {
         if (!$this->call('RCPT TO:<' . $email . '>', 250, 251)) {
             $this->disconnect();
             //throw exception
             Exception::i()->setMessage(Exception::SMTP_ADD_EMAIL)->addVariable($email)->trigger();
         }
     }
     //add bcc
     foreach ($this->bcc as $email => $name) {
         if (!$this->call('RCPT TO:<' . $email . '>', 250, 251)) {
             $this->disconnect();
             //throw exception
             Exception::i()->setMessage(Exception::SMTP_ADD_EMAIL)->addVariable($email)->trigger();
         }
     }
     //start compose
     if (!$this->call('DATA', 354)) {
         $this->disconnect();
         //throw exception
         Exception::i(Exception::SMTP_DATA)->trigger();
     }
     //send header data
     foreach ($headers as $name => $value) {
         $this->push($name . ': ' . $value);
     }
     //send body data
     foreach ($body as $line) {
         if (strpos($line, '.') === 0) {
             // Escape lines prefixed with a '.'
             $line = '.' . $line;
         }
         $this->push($line);
     }
     //tell server this is the end
     if (!$this->call(".", 250)) {
         $this->disconnect();
         //throw exception
         Exception::i(Exception::SMTP_DATA)->trigger();
     }
     //reset (some reason without this, this class spazzes out)
     $this->push('RSET');
     return $headers;
 }
开发者ID:kamaroly,项目名称:Mail,代码行数:74,代码来源:Smtp.php

示例7: connect

 /**
  * Connects to the server
  *
  * @param int  $timeout The connection timeout
  * @param bool $test    Whether to output the logs
  *
  * @return Eden\Mail\Imap
  */
 public function connect($timeout = self::TIMEOUT, $test = false)
 {
     Argument::i()->test(1, 'int')->test(2, 'bool');
     if ($this->socket) {
         return $this;
     }
     $host = $this->host;
     if ($this->ssl) {
         $host = 'ssl://' . $host;
     }
     $errno = 0;
     $errstr = '';
     $this->socket = @fsockopen($host, $this->port, $errno, $errstr, $timeout);
     if (!$this->socket) {
         //throw exception
         Exception::i()->setMessage(Exception::SERVER_ERROR)->addVariable($host . ':' . $this->port)->trigger();
     }
     if (strpos($this->getLine(), '* OK') === false) {
         $this->disconnect();
         //throw exception
         Exception::i()->setMessage(Exception::SERVER_ERROR)->addVariable($host . ':' . $this->port)->trigger();
     }
     if ($this->tls) {
         $this->send('STARTTLS');
         if (!stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
             $this->disconnect();
             //throw exception
             Exception::i()->setMessage(Exception::TLS_ERROR)->addVariable($host . ':' . $this->port)->trigger();
         }
     }
     if ($test) {
         fclose($this->socket);
         $this->socket = null;
         return $this;
     }
     //login
     $result = $this->call('LOGIN', $this->escape($this->username, $this->password));
     if (!is_array($result) || strpos(implode(' ', $result), 'OK') === false) {
         $this->disconnect();
         //throw exception
         Exception::i(Exception::LOGIN_ERROR)->trigger();
     }
     return $this;
 }
开发者ID:kamaroly,项目名称:Mail,代码行数:52,代码来源:Imap.php

示例8: virtual

 /**
  * Tests virtual arguments for valid data types
  *
  * @param *string          $method method name
  * @param *array           $args   arguments
  * @param *int             $index  the argument index to test for
  * @param *mixed[,mixed..] $types  the types to test for
  *
  * @return Eden\Core\Argument
  */
 public function virtual($method, array $args, $index, $types)
 {
     //if no test
     if (static::$stop) {
         return $this;
     }
     $offset = 1;
     //if the trace came from Argument->test()
     if (isset($trace['class'], $trace['function']) && $trace['class'] == __CLASS__ && $trace['function'] == 'test') {
         //go back one more
         $offset = 2;
     }
     $trace = debug_backtrace();
     $trace = $trace[$offset];
     $types = func_get_args();
     $method = array_shift($types);
     $args = array_shift($types);
     $index = array_shift($types) - 1;
     if ($index < 0) {
         $index = 0;
     }
     //if it's not set then it's good because the default value
     //set in the method will be it.
     if ($index >= count($args)) {
         return $this;
     }
     $argument = $args[$index];
     foreach ($types as $i => $type) {
         if ($this->isValid($type, $argument)) {
             return $this;
         }
     }
     if (strpos($method, '->') === false && isset($trace['class'])) {
         $method = $trace['class'] . '->' . $method;
     }
     $type = $this->getDataType($argument);
     Exception::i()->setMessage(self::INVALID_ARGUMENT)->addVariable($index + 1)->addVariable($method)->addVariable(implode(' or ', $types))->addVariable($type)->setTypeLogic()->setTraceOffset($offset)->trigger();
 }
开发者ID:eden-php,项目名称:core,代码行数:48,代码来源:Argument.php

示例9: connect

 /**
  * Connects to the server
  *
  * @param bool $test Whether to output the logs
  *
  * @return Eden\Mail\Pop3
  */
 public function connect($test = false)
 {
     Argument::i()->test(1, 'bool');
     if ($this->loggedin) {
         return $this;
     }
     $host = $this->host;
     if ($this->ssl) {
         $host = 'ssl://' . $host;
     }
     $errno = 0;
     $errstr = '';
     $this->socket = fsockopen($host, $this->port, $errno, $errstr, self::TIMEOUT);
     if (!$this->socket) {
         //throw exception
         Exception::i()->setMessage(Exception::SERVER_ERROR)->addVariable($host . ':' . $this->port)->trigger();
     }
     $welcome = $this->receive();
     strtok($welcome, '<');
     $this->timestamp = strtok('>');
     if (!strpos($this->timestamp, '@')) {
         $this->timestamp = null;
     } else {
         $this->timestamp = '<' . $this->timestamp . '>';
     }
     if ($this->tls) {
         $this->call('STLS');
         if (!stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
             $this->disconnect();
             //throw exception
             Exception::i()->setMessage(Exception::TLS_ERROR)->addVariable($host . ':' . $this->port)->trigger();
         }
     }
     if ($test) {
         $this->disconnect();
         return $this;
     }
     //login
     if ($this->timestamp) {
         try {
             $this->call('APOP ' . $this->username . ' ' . md5($this->timestamp . $this->password));
             return;
         } catch (Argument $e) {
             // ignore
         }
     }
     $this->call('USER ' . $this->username);
     $this->call('PASS ' . $this->password);
     $this->loggedin = true;
     return $this;
 }
开发者ID:kamaroly,项目名称:Mail,代码行数:58,代码来源:Pop3.php

示例10: valid

 /**
  * Validates whether if the index is set
  * For Iterator interface
  *
  * @return bool
  */
 public function valid()
 {
     if (!self::$session) {
         Exception::i()->setMessage(self::ERROR_NOT_STARTED)->trigger();
     }
     return isset($_SESSION[$this->key()]);
 }
开发者ID:Eden-PHP,项目名称:Session,代码行数:13,代码来源:Index.php

示例11: process

 /**
  * Starts to process the request
  *
  * @return array with request and response inside
  */
 public function process()
 {
     //formulate the request and response
     $request = $this->getRequest();
     $response = $this->getResponse();
     //register shutdown
     register_shutdown_function(function ($server) {
         $server->trigger('server-end');
     }, $this);
     //if it's not a child
     if (!$this->parentServer instanceof Index) {
         //handle errors in case
         $this->handleErrors($request, $response);
     }
     //if we are Good, route
     if ($this->processGlobal($request, $response)) {
         //if no routing on this
         if (!$this->processRoutes($request, $response)) {
             $response->set('code', 404);
             //throw an exception
             Exception::i()->setMessage(self::NOT_FOUND)->setType(self::RESPONSE_ERROR_TYPE)->trigger();
         }
     }
     //do we have a body ?
     $body = $response->get('body');
     if ($body === null || !is_scalar($body) || !strlen((string) $body)) {
         $response->set('code', 404);
         //throw an exception
         Exception::i()->setMessage(self::NOT_FOUND)->setType(self::RESPONSE_ERROR_TYPE)->trigger();
     }
     return array($request, $response);
 }
开发者ID:Eden-PHP,项目名称:Server,代码行数:37,代码来源:Index.php

示例12: dialog

 /**
  * Opens the browsers auth dialig
  *
  * @return void
  */
 public function dialog()
 {
     //if session has not started
     if (!session_id()) {
         //start session
         session_start();
     }
     //if they never tried
     if (!isset($_SESSION[self::UNAUTHORIZED])) {
         //first try
         $_SESSION[self::UNAUTHORIZED] = 1;
     } else {
         //more than one try
         $_SESSION[self::UNAUTHORIZED]++;
     }
     //if it's their first few tries
     if ($_SESSION[self::UNAUTHORIZED] < 3) {
         header(sprintf(self::HTTP_AUTH, $this->realm, uniqid(), md5($this->realm)));
         exit;
     }
     //let them try again
     unset($_SESSION[self::UNAUTHORIZED]);
     //you are unauthorized
     header(self::UNAUTHORIZED);
     //throw
     Exception::i()->setMessage(self::UNAUTHORIZED)->setType(self::ERROR_TYPE)->trigger();
 }
开发者ID:eve-php,项目名称:eve-plugin-htpasswd,代码行数:32,代码来源:Setup.php

示例13: exception

 /**
  * Returns the exception class
  *
  * @return Eden\Handler\Exception
  */
 public function exception()
 {
     return Exception::i();
 }
开发者ID:Eden-PHP,项目名称:Handler,代码行数:9,代码来源:Index.php

示例14: getInstance

 /**
  * Returns an instance considering routes. With
  * this method we can instantiate while passing
  * construct arguments as arrays
  *
  * @param *string $class name of the class
  *
  * @return object
  */
 private static function getInstance($class)
 {
     //get the backtrace
     $trace = debug_backtrace();
     $args = array();
     //the 2nd line is the caller method
     if (isset($trace[1]['args']) && count($trace[1]['args']) > 1) {
         //get the args
         $args = $trace[1]['args'];
         //shift out the class name
         array_shift($args);
         //then maybe it's the 3rd line?
     } else {
         if (isset($trace[2]['args']) && count($trace[2]['args']) > 0) {
             //get the args
             $args = $trace[2]['args'];
         }
     }
     //if there's no args or there's no construct to accept the args
     if (count($args) === 0 || !method_exists($class, '__construct')) {
         //just return the instantiation
         return new $class();
     }
     //at this point, we need to vitually call the class
     $reflect = new \ReflectionClass($class);
     try {
         //to return the instantiation
         return $reflect->newInstanceArgs($args);
     } catch (\ReflectionException $e) {
         //trigger error
         Exception::i()->setMessage(self::ERROR_REFLECTION)->addVariable($class)->addVariable('new')->trigger();
     }
 }
开发者ID:eden-php,项目名称:core,代码行数:42,代码来源:Base.php


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