Beispiel #1
0
/**
 *  Cast a PHP runtime value to an ecmascript value
 *
 *  @param  input   the value to cast
 *  @return v8::Handle<v8::Value>
 */
v8::Handle<v8::Value> value(const Php::Value &input)
{
    // create a handle that we can return a value from
    v8::EscapableHandleScope    scope(Isolate::get());

    // the result value we are assigning
    v8::Local<v8::Value>        result;

    // are we dealing with a value originally from ecmascript?
    if (input.instanceOf("JS\\Object"))
    {
        // cast the input to the original object
        result = static_cast<JSObject*>(input.implementation())->object();
    }
    else
    {
        // the value can be of many types
        switch (input.type())
        {
            case Php::Type::Null:       /* don't set anything, let it be empty */                                                   break;
            case Php::Type::Numeric:    result = v8::Integer::New(Isolate::get(), input);                                           break;
            case Php::Type::Float:      result = v8::Number::New(Isolate::get(), input);                                            break;
            case Php::Type::Bool:       result = v8::Boolean::New(Isolate::get(), input);                                           break;
            case Php::Type::String:     result = v8::String::NewFromUtf8(Isolate::get(), input);                                    break;
            case Php::Type::Object:     result = Object(input);                                                                     break;
            case Php::Type::Callable:   result = v8::FunctionTemplate::New(Isolate::get(), callback, Handle(input))->GetFunction(); break;
            case Php::Type::Array:      result = Array(input);                                                                      break;
            default:
                break;
        }
    }

    // return the value by "escaping" it
    return scope.Escape(result);
}
Beispiel #2
0
    Php::Value sub(Php::Parameters &params) {
        Php::Value t = params[0];
        Complex *a = (Complex *) t.implementation();

        r -= (double) a->getReal();
        i -= (double) a->getImage();

        return this;
    }
Beispiel #3
0
	void DI::setDefault(Php::Parameters &params)
	{
		try {
			Php::Value value = params.at(0);
			_default = (DI *) value.implementation();
		} catch (const std::out_of_range& e) {
			throw Php::Exception("Invalid number of parameters supplied");
		}
	}
Beispiel #4
0
    Php::Value mul(Php::Parameters &params) {
        Php::Value t = params[0];
        Complex *a = (Complex *) t.implementation();

        double tr = r * (double) (a->getReal()) - i * (double) (a->getImage());
        double ti = i * (double) (a->getReal()) + r * (double) (a->getImage());

        r = tr;
        i = ti;
        return this;
    }
Beispiel #5
0
    Php::Value div(Php::Parameters &params) {
        Php::Value t = params[0];
        Complex *b = (Complex*) t.implementation();

        double t1 = b->mod() * b->mod();

        if (t1 < EPS)
            throw Php::Exception("Division by zero");

        double tr = r * (double) (b->getReal()) + i * (double) (b->getImage());
        double ti = i * (double) (b->getReal()) - r * (double) (b->getImage());

        r = tr / t1;
        i = ti / t1;

        return this;
    }