Пример #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);
}
Пример #2
0
void Connection::__construct(Php::Parameters &params)
{
	this->_options = params[0];

	Php::Value host_string = this->_options.get("hosts");
	Php::Value port = CASSANDRA_DEFAULT_PORT;

	if (this->_options.contains("port")) {
		port = this->_options.get("port");
	}

	if (!host_string.isString()) {
		throw Php::Exception("Host string parameter not a string");
	}

	if (!port.isNumeric()) {
		throw Php::Exception("Port is not a number");
	}

	if (this->_options.contains("logger")) {
		this->_logger = this->_options.get("logger");
	}

	// Call the c++ constructor with the provided php values
	init(host_string.stringValue(), port.numericValue());
}
Пример #3
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;
    }
Пример #4
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");
		}
	}
Пример #5
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;
    }
Пример #6
0
    Php::Value StructSchema::getFieldNames() {
        Php::Value result;

        auto fields = schema.getFields();

        for(capnp::uint i = 0; i < fields.size(); ++i) {
            result.set(i, DynamicValueConverter::convertTextToPhpString(fields[i].getProto().getName()));
        }

        return result;
    }
Пример #7
0
/**
 *  PHP Constructor
 *  @param Php::Parameters &parameters
 */
void FastImage::__construct(Php::Parameters &parameters)
{
	Php::Value self(this);

	Php::Value input = parameters[0];

	inputFile = input.stringValue();
	cvImage = cv::imread(inputFile);

	if (cvImage.empty()) {
		std::string message = (std::string)"FastImage: File "+ inputFile + (std::string)" not found.";

		throw Php::Exception(message);
	}
}
Пример #8
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;
    }
/**
 *  Turn into a Php::Value
 *  @return Php::Value
 */
Php::Value Array::phpValue() const
{
    // create an output value
    Php::Value output;

    // loop over the entire array
    for (int i = 0; i < size(); ++i)
    {
        // switch through all the types and add them to the php value
        switch (type(i))
        {
        case JSON::Type::Null:    output.set(i, nullptr);              break;
        case JSON::Type::Boolean: output.set(i, boolean(i));           break;
        case JSON::Type::Decimal: output.set(i, decimal(i));           break;
        case JSON::Type::Integer: output.set(i, integer(i));           break;
        case JSON::Type::String:  output.set(i, c_str(i));             break;
        case JSON::Type::Array:   output.set(i, array(i).phpValue());  break;
        case JSON::Type::Object:  output.set(i, object(i).phpValue()); break;
        default:                                                       break;
        }
    }

    // return our output
    return output;
}