Skip to content

Commit

Permalink
Merge branch 'master' of github.com:CopernicaMarketingSoftware/PHP-CP…
Browse files Browse the repository at this point in the history
…P-LEGACY
  • Loading branch information
EmielBruijntjes committed Apr 19, 2019
2 parents d69b1e0 + 87dc159 commit 2e4fafd
Show file tree
Hide file tree
Showing 21 changed files with 252 additions and 200 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ INSTALL_LIB = ${INSTALL_PREFIX}/lib
# Otherwise only release verions changes. (version is MAJOR.MINOR.RELEASE)
#

SONAME = 1.6
VERSION = 1.6.5
SONAME = 1.7
VERSION = 1.7.0


#
Expand Down
10 changes: 5 additions & 5 deletions include/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PHPCPP_EXPORT Array : public Value
Array(const Value &value) : Value(value)
{
// type must be valid
if (value.type() != Type::Array) throw FatalError("Assigning a non-array to an array variable");
if (value.type() != Type::Array) throw Error("Assigning a non-array to an array variable");
}

/**
Expand All @@ -41,7 +41,7 @@ class PHPCPP_EXPORT Array : public Value
Array(Value &&value) : Value(std::move(value))
{
// type must be valid
if (value.type() != Type::Array) throw FatalError("Moving a non-array to an array variable");
if (value.type() != Type::Array) throw Error("Moving a non-array to an array variable");
}

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ class PHPCPP_EXPORT Array : public Value
virtual Value &setType(Type type) override
{
// throw exception if things are going wrong
if (type != Type::Array) throw FatalError("Changing type of a fixed array variable");
if (type != Type::Array) throw Error("Changing type of a fixed array variable");

// call base
return Value::setType(Type::Array);
Expand All @@ -99,7 +99,7 @@ class PHPCPP_EXPORT Array : public Value
if (this == &value) return *this;

// type must be valid
if (value.type() != Type::Array) throw FatalError("Assigning a non-array to a fixed array variable");
if (value.type() != Type::Array) throw Error("Assigning a non-array to a fixed array variable");

// call base
Value::operator=(value);
Expand All @@ -119,7 +119,7 @@ class PHPCPP_EXPORT Array : public Value
if (this == &value) return *this;

// type must be valid
if (value.type() != Type::Array) throw FatalError("Moving a non-array to a fixed array variable");
if (value.type() != Type::Array) throw Error("Moving a non-array to a fixed array variable");

// call base
Value::operator=(std::move(value));
Expand Down
4 changes: 2 additions & 2 deletions include/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ inline PHPCPP_EXPORT Value require(const std::string &filename) { return requ
extern PHPCPP_EXPORT Value require_once(const char *filename);
inline PHPCPP_EXPORT Value require_once(const std::string &filename) { return require_once(filename.c_str()); }
extern PHPCPP_EXPORT Value set_exception_handler(const std::function<Value(Parameters &params)> &handler);
extern PHPCPP_EXPORT Value set_error_handler(const std::function<Value(Parameters &params)> &handler, Error error = Error::All);
extern PHPCPP_EXPORT Value error_reporting(Error error);
extern PHPCPP_EXPORT Value set_error_handler(const std::function<Value(Parameters &params)> &handler, Message message = Message::All);
extern PHPCPP_EXPORT Value error_reporting(Message message);
extern PHPCPP_EXPORT const char *sapi_name();

/**
Expand Down
69 changes: 69 additions & 0 deletions include/error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Error.h
*
* In PHP7 errors are thrown as Error objects, while in PHP5 errors immediately
* cause a fatal crash. Because the PHP-CPP-LEGACY class only supports PHP5,
* the Error class in this file is thus never thrown from PHP space to C++ space.
*
* But to ensure that an extension can be compiled on PHP5 and PHP7, we have
* still added it to the source code, so that it will not cause compile
* errors.
*
* But you can use it to throw fatal errors.
*
* @author Emiel Bruijntjes <[email protected]>
* @copyright 2019 Copernica BV
*/

/**
* Include guard
*/
#pragma once

/**
* Begin of namespace
*/
namespace Php {

/**
* Class definition
*/
class PHPCPP_EXPORT Error : public Throwable
{
public:
/**
* Constructor
* @param message
* @param code
*/
Error(const std::string &message, int code = 0) : Throwable(message, code) {}

/**
* Destructor
*/
virtual ~Error() = default;

/**
* Is this a native exception (one that was thrown from C++ code)
* @return bool
*/
virtual bool native() const
{
// although it is native, we return 0 because it should not persist
// as exception, but it should live on as zend_error() in stead
return false;
}

/**
* Report this error as a fatal error
* @return bool
*/
virtual bool report() const override;

};

/**
* End of namespace
*/
}

85 changes: 18 additions & 67 deletions include/exception.h
Original file line number Diff line number Diff line change
@@ -1,93 +1,44 @@
/**
* Exception.h
* Implementation of Php Exceptions.
*
* @author Jasper van Eck <[email protected]>
* @copyright 2013, 2014 Copernica BV
* Exception class that can be thrown and caught in C++ space and that
* will end up in or can originate from PHP space.
*
* @author Emiel Bruijntjes <[email protected]>
* @copyright 2019 Copernica BV
*/

/**
* Include guard
*/
#include <exception>
#pragma once

/**
* Set up namespace
* Begin of namespace
*/
namespace Php {

/**
* Class definition
*/
class PHPCPP_EXPORT Exception : public std::exception
class PHPCPP_EXPORT Exception : public Throwable
{
private:
/**
* The exception message
* @var char*
*/
std::string _message;

/**
* The PHP exception code
* @var int
*/
int _code;

/**
* Has this exception been processed by native C++ code?
* @var bool
*/
bool _processed = false;

public:
/**
* Constructor
* @param &string
* @param message
* @param code
*/
Exception(const std::string &message, int code = 0) : std::exception(), _message(message), _code(code) {}

Exception(const std::string &message, int code = 0) : Throwable(message, code) {}
/**
* Destructor
*/
virtual ~Exception() throw() {}

/**
* Overridden what method
* @return const char *
*/
virtual const char *what() const _NOEXCEPT override
{
return _message.c_str();
}

/**
* Returns the message of the exception.
* @return &string
*/
const std::string &message() const throw()
{
return _message;
}

/**
* Is this a native exception (one that was thrown from C++ code)
* @return bool
*/
virtual bool native() const
{
// yes, it is native
return true;
}

/**
* Report this error as a fatal error
* @return bool
*/
virtual bool report() const
{
// this is not done here
return false;
}
virtual ~Exception() = default;
};

/**
* End of namespace
*/
}

65 changes: 0 additions & 65 deletions include/fatalerror.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/errors.h → include/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Php {
/**
* Supported types of errors, this is mostly a copy from Zend/zend_errors.h
*/
enum class PHPCPP_EXPORT Error : int {
enum class PHPCPP_EXPORT Message : int {
Error = (1 << 0L),
Warning = (1 << 1L),
Parse = (1 << 2L),
Expand Down
6 changes: 3 additions & 3 deletions include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PHPCPP_EXPORT Object : public Value
virtual Value &setType(Type type) override
{
// throw exception if things are going wrong
if (type != Type::Object) throw FatalError("Changing type of a fixed object variable");
if (type != Type::Object) throw Error("Changing type of a fixed object variable");

// call base
return Value::setType(type);
Expand All @@ -126,7 +126,7 @@ class PHPCPP_EXPORT Object : public Value
if (this == &value) return *this;

// type must be valid
if (value.type() != Type::Object) throw FatalError("Assigning a non-object to an object variable");
if (value.type() != Type::Object) throw Error("Assigning a non-object to an object variable");

// call base
Value::operator=(value);
Expand All @@ -146,7 +146,7 @@ class PHPCPP_EXPORT Object : public Value
if (this == &value) return *this;

// type must be valid
if (value.type() != Type::Object) throw FatalError("Moving a non-object to an object variable");
if (value.type() != Type::Object) throw Error("Moving a non-object to an object variable");

// call base
Value::operator=(std::move(value));
Expand Down
Loading

0 comments on commit 2e4fafd

Please sign in to comment.