diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-04 18:21:58 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-04 18:21:58 +0100 |
commit | c028e8f932cc4206ab8446409693fba8dfe18ffb (patch) | |
tree | 4ffe8a5d77888cff291eb7dd412bbd03e51c6f29 /src/object.cpp | |
parent | 200952ad4004f6ee5527598622505adbe84df8af (diff) |
Php::Value and Php::Object classes can now be used to wrap around Php::Base objects
Diffstat (limited to 'src/object.cpp')
-rw-r--r-- | src/object.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/object.cpp b/src/object.cpp index aa99c0d..f1bcdf8 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -12,6 +12,36 @@ namespace Php { /** + * Constructor to create a new instance of a builtin class + * + * @param name Name of the class to instantiate + * @param base Implementation of the class + */ +Object::Object(const char *name, Base *base) +{ + // does the object already have a handle? + if (base->handle()) + { + // the object is already instantiated, we can assign it the this object + operator=(Value(base)); + } + else + { + // this is a brand new object that should be allocated, the C++ instance + // is already there (created by the extension) but it is not yet stored + // in PHP, find out the classname first + auto *entry = zend_fetch_class(name, strlen(name), 0); + if (!entry) throw Php::Exception(std::string("Unknown class name ") + name); + + // store the object in the php object cache (this will give the object a handle) + base->store(entry); + + // now we can store it + operator=(Value(base)); + } +} + +/** * Internal method to instantiate an object * @param name */ |