~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to php/src/IcePHP/Properties.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// **********************************************************************
 
2
//
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
 
4
//
 
5
// This copy of Ice is licensed to you under the terms described in the
 
6
// ICE_LICENSE file included in this distribution.
 
7
//
 
8
// **********************************************************************
 
9
 
 
10
#include <Properties.h>
 
11
#include <Util.h>
 
12
 
 
13
using namespace std;
 
14
using namespace IcePHP;
 
15
 
 
16
ZEND_EXTERN_MODULE_GLOBALS(ice)
 
17
 
 
18
//
 
19
// Class entries represent the PHP class implementations we have registered.
 
20
//
 
21
namespace IcePHP
 
22
{
 
23
zend_class_entry* propertiesClassEntry = 0;
 
24
}
 
25
 
 
26
//
 
27
// Properties support.
 
28
//
 
29
static zend_object_handlers _handlers;
 
30
 
 
31
extern "C"
 
32
{
 
33
static zend_object_value handleAlloc(zend_class_entry* TSRMLS_DC);
 
34
static void handleFreeStorage(void* TSRMLS_DC);
 
35
static zend_object_value handleClone(zval* TSRMLS_DC);
 
36
}
 
37
 
 
38
ZEND_METHOD(Ice_Properties, __construct)
 
39
{
 
40
    runtimeError("properties objects cannot be instantiated, use createProperties()" TSRMLS_CC);
 
41
}
 
42
 
 
43
ZEND_METHOD(Ice_Properties, __toString)
 
44
{
 
45
    if(ZEND_NUM_ARGS() > 0)
 
46
    {
 
47
        WRONG_PARAM_COUNT;
 
48
    }
 
49
 
 
50
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
51
    assert(_this);
 
52
 
 
53
    try
 
54
    {
 
55
        Ice::PropertyDict val = _this->getPropertiesForPrefix("");
 
56
        string str;
 
57
        for(Ice::PropertyDict::const_iterator p = val.begin(); p != val.end(); ++p)
 
58
        {
 
59
            if(p != val.begin())
 
60
            {
 
61
                str.append("\n");
 
62
            }
 
63
            str.append(p->first + "=" + p->second);
 
64
        }
 
65
        RETURN_STRINGL(STRCAST(str.c_str()), str.length(), 1);
 
66
    }
 
67
    catch(const IceUtil::Exception& ex)
 
68
    {
 
69
        throwException(ex TSRMLS_CC);
 
70
        RETURN_NULL();
 
71
    }
 
72
}
 
73
 
 
74
ZEND_METHOD(Ice_Properties, getProperty)
 
75
{
 
76
    char* name;
 
77
    int nameLen;
 
78
 
 
79
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("s"), &name, &nameLen) == FAILURE)
 
80
    {
 
81
        RETURN_NULL();
 
82
    }
 
83
 
 
84
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
85
    assert(_this);
 
86
 
 
87
    string propName(name, nameLen);
 
88
    try
 
89
    {
 
90
        string val = _this->getProperty(propName);
 
91
        RETURN_STRINGL(STRCAST(val.c_str()), val.length(), 1);
 
92
    }
 
93
    catch(const IceUtil::Exception& ex)
 
94
    {
 
95
        throwException(ex TSRMLS_CC);
 
96
        RETURN_NULL();
 
97
    }
 
98
}
 
99
 
 
100
ZEND_METHOD(Ice_Properties, getPropertyWithDefault)
 
101
{
 
102
    char* name;
 
103
    int nameLen;
 
104
    char* def;
 
105
    int defLen;
 
106
 
 
107
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("ss!"), &name, &nameLen, &def, &defLen) ==
 
108
        FAILURE)
 
109
    {
 
110
        RETURN_NULL();
 
111
    }
 
112
 
 
113
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
114
    assert(_this);
 
115
 
 
116
    string propName(name, nameLen);
 
117
    string defaultValue;
 
118
    if(def)
 
119
    {
 
120
        defaultValue = string(def, defLen);
 
121
    }
 
122
 
 
123
    try
 
124
    {
 
125
        string val = _this->getPropertyWithDefault(propName, defaultValue);
 
126
        RETURN_STRINGL(STRCAST(val.c_str()), val.length(), 1);
 
127
    }
 
128
    catch(const IceUtil::Exception& ex)
 
129
    {
 
130
        throwException(ex TSRMLS_CC);
 
131
        RETURN_NULL();
 
132
    }
 
133
}
 
134
 
 
135
ZEND_METHOD(Ice_Properties, getPropertyAsInt)
 
136
{
 
137
    char* name;
 
138
    int nameLen;
 
139
 
 
140
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("s"), &name, &nameLen) == FAILURE)
 
141
    {
 
142
        RETURN_NULL();
 
143
    }
 
144
 
 
145
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
146
    assert(_this);
 
147
 
 
148
    string propName(name, nameLen);
 
149
    try
 
150
    {
 
151
        Ice::Int val = _this->getPropertyAsInt(propName);
 
152
        RETURN_LONG(static_cast<long>(val));
 
153
    }
 
154
    catch(const IceUtil::Exception& ex)
 
155
    {
 
156
        throwException(ex TSRMLS_CC);
 
157
        RETURN_NULL();
 
158
    }
 
159
}
 
160
 
 
161
ZEND_METHOD(Ice_Properties, getPropertyAsIntWithDefault)
 
162
{
 
163
    char* name;
 
164
    int nameLen;
 
165
    long def;
 
166
 
 
167
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("sl"), &name, &nameLen, &def) == FAILURE)
 
168
    {
 
169
        RETURN_NULL();
 
170
    }
 
171
 
 
172
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
173
    assert(_this);
 
174
 
 
175
    string propName(name, nameLen);
 
176
    try
 
177
    {
 
178
        Ice::Int val = _this->getPropertyAsIntWithDefault(propName, def);
 
179
        RETURN_LONG(static_cast<long>(val));
 
180
    }
 
181
    catch(const IceUtil::Exception& ex)
 
182
    {
 
183
        throwException(ex TSRMLS_CC);
 
184
        RETURN_NULL();
 
185
    }
 
186
}
 
187
 
 
188
ZEND_METHOD(Ice_Properties, getPropertyAsList)
 
189
{
 
190
    char* name;
 
191
    int nameLen;
 
192
 
 
193
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("s"), &name, &nameLen) == FAILURE)
 
194
    {
 
195
        RETURN_NULL();
 
196
    }
 
197
 
 
198
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
199
    assert(_this);
 
200
 
 
201
    string propName(name, nameLen);
 
202
    try
 
203
    {
 
204
        Ice::StringSeq val = _this->getPropertyAsList(propName);
 
205
        if(!createStringArray(return_value, val TSRMLS_CC))
 
206
        {
 
207
            RETURN_NULL();
 
208
        }
 
209
    }
 
210
    catch(const IceUtil::Exception& ex)
 
211
    {
 
212
        throwException(ex TSRMLS_CC);
 
213
        RETURN_NULL();
 
214
    }
 
215
}
 
216
 
 
217
ZEND_METHOD(Ice_Properties, getPropertyAsListWithDefault)
 
218
{
 
219
    char* name;
 
220
    int nameLen;
 
221
    zval* def;
 
222
 
 
223
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("sa!"), &name, &nameLen, &def) == FAILURE)
 
224
    {
 
225
        RETURN_NULL();
 
226
    }
 
227
 
 
228
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
229
    assert(_this);
 
230
 
 
231
    string propName(name, nameLen);
 
232
    Ice::StringSeq defaultValue;
 
233
    if(def && !extractStringArray(def, defaultValue TSRMLS_CC))
 
234
    {
 
235
        RETURN_NULL();
 
236
    }
 
237
 
 
238
    try
 
239
    {
 
240
        Ice::StringSeq val = _this->getPropertyAsListWithDefault(propName, defaultValue);
 
241
        if(!createStringArray(return_value, val TSRMLS_CC))
 
242
        {
 
243
            RETURN_NULL();
 
244
        }
 
245
    }
 
246
    catch(const IceUtil::Exception& ex)
 
247
    {
 
248
        throwException(ex TSRMLS_CC);
 
249
        RETURN_NULL();
 
250
    }
 
251
}
 
252
 
 
253
ZEND_METHOD(Ice_Properties, getPropertiesForPrefix)
 
254
{
 
255
    char* p;
 
256
    int pLen;
 
257
 
 
258
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("s!"), &p, &pLen) == FAILURE)
 
259
    {
 
260
        RETURN_NULL();
 
261
    }
 
262
 
 
263
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
264
    assert(_this);
 
265
 
 
266
    string prefix;
 
267
    if(p)
 
268
    {
 
269
        prefix = string(p, pLen);
 
270
    }
 
271
 
 
272
    try
 
273
    {
 
274
        Ice::PropertyDict val = _this->getPropertiesForPrefix(prefix);
 
275
        if(!createStringMap(return_value, val TSRMLS_CC))
 
276
        {
 
277
            RETURN_NULL();
 
278
        }
 
279
    }
 
280
    catch(const IceUtil::Exception& ex)
 
281
    {
 
282
        throwException(ex TSRMLS_CC);
 
283
        RETURN_NULL();
 
284
    }
 
285
}
 
286
 
 
287
ZEND_METHOD(Ice_Properties, setProperty)
 
288
{
 
289
    char* name;
 
290
    int nameLen;
 
291
    char* val;
 
292
    int valLen;
 
293
 
 
294
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("ss!"), &name, &nameLen, &val, &valLen) ==
 
295
        FAILURE)
 
296
    {
 
297
        RETURN_NULL();
 
298
    }
 
299
 
 
300
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
301
    assert(_this);
 
302
 
 
303
    string propName(name, nameLen);
 
304
    string propValue;
 
305
    if(val)
 
306
    {
 
307
        propValue = string(val, valLen);
 
308
    }
 
309
 
 
310
    try
 
311
    {
 
312
        _this->setProperty(propName, propValue);
 
313
    }
 
314
    catch(const IceUtil::Exception& ex)
 
315
    {
 
316
        throwException(ex TSRMLS_CC);
 
317
        RETURN_NULL();
 
318
    }
 
319
}
 
320
 
 
321
ZEND_METHOD(Ice_Properties, getCommandLineOptions)
 
322
{
 
323
    if(ZEND_NUM_ARGS() != 0)
 
324
    {
 
325
        WRONG_PARAM_COUNT;
 
326
    }
 
327
 
 
328
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
329
    assert(_this);
 
330
 
 
331
    try
 
332
    {
 
333
        Ice::StringSeq val = _this->getCommandLineOptions();
 
334
        if(!createStringArray(return_value, val TSRMLS_CC))
 
335
        {
 
336
            RETURN_NULL();
 
337
        }
 
338
    }
 
339
    catch(const IceUtil::Exception& ex)
 
340
    {
 
341
        throwException(ex TSRMLS_CC);
 
342
        RETURN_NULL();
 
343
    }
 
344
}
 
345
 
 
346
ZEND_METHOD(Ice_Properties, parseCommandLineOptions)
 
347
{
 
348
    char* p;
 
349
    int pLen;
 
350
    zval* opts;
 
351
 
 
352
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("s!a!"), &p, &pLen, &opts) == FAILURE)
 
353
    {
 
354
        RETURN_NULL();
 
355
    }
 
356
 
 
357
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
358
    assert(_this);
 
359
 
 
360
    string prefix;
 
361
    if(p)
 
362
    {
 
363
        prefix = string(p, pLen);
 
364
    }
 
365
    Ice::StringSeq options;
 
366
    if(opts && !extractStringArray(opts, options TSRMLS_CC))
 
367
    {
 
368
        RETURN_NULL();
 
369
    }
 
370
 
 
371
    try
 
372
    {
 
373
        Ice::StringSeq val = _this->parseCommandLineOptions(prefix, options);
 
374
        if(!createStringArray(return_value, val TSRMLS_CC))
 
375
        {
 
376
            RETURN_NULL();
 
377
        }
 
378
    }
 
379
    catch(const IceUtil::Exception& ex)
 
380
    {
 
381
        throwException(ex TSRMLS_CC);
 
382
        RETURN_NULL();
 
383
    }
 
384
}
 
385
 
 
386
ZEND_METHOD(Ice_Properties, parseIceCommandLineOptions)
 
387
{
 
388
    zval* opts;
 
389
 
 
390
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("a!"), &opts) == FAILURE)
 
391
    {
 
392
        RETURN_NULL();
 
393
    }
 
394
 
 
395
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
396
    assert(_this);
 
397
 
 
398
    Ice::StringSeq options;
 
399
    if(opts && !extractStringArray(opts, options TSRMLS_CC))
 
400
    {
 
401
        RETURN_NULL();
 
402
    }
 
403
 
 
404
    try
 
405
    {
 
406
        Ice::StringSeq val = _this->parseIceCommandLineOptions(options);
 
407
        if(!createStringArray(return_value, val TSRMLS_CC))
 
408
        {
 
409
            RETURN_NULL();
 
410
        }
 
411
    }
 
412
    catch(const IceUtil::Exception& ex)
 
413
    {
 
414
        throwException(ex TSRMLS_CC);
 
415
        RETURN_NULL();
 
416
    }
 
417
}
 
418
 
 
419
ZEND_METHOD(Ice_Properties, load)
 
420
{
 
421
    char* f;
 
422
    int fLen;
 
423
 
 
424
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("s"), &f, &fLen) == FAILURE)
 
425
    {
 
426
        RETURN_NULL();
 
427
    }
 
428
 
 
429
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
430
    assert(_this);
 
431
 
 
432
    string file(f, fLen);
 
433
 
 
434
    try
 
435
    {
 
436
        _this->load(file);
 
437
    }
 
438
    catch(const IceUtil::Exception& ex)
 
439
    {
 
440
        throwException(ex TSRMLS_CC);
 
441
        RETURN_NULL();
 
442
    }
 
443
}
 
444
 
 
445
ZEND_METHOD(Ice_Properties, clone)
 
446
{
 
447
    if(ZEND_NUM_ARGS() > 0)
 
448
    {
 
449
        WRONG_PARAM_COUNT;
 
450
    }
 
451
 
 
452
    Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis() TSRMLS_CC);
 
453
    assert(_this);
 
454
 
 
455
    try
 
456
    {
 
457
        Ice::PropertiesPtr pclone = _this->clone();
 
458
 
 
459
        if(!createProperties(return_value, pclone TSRMLS_CC))
 
460
        {
 
461
            RETURN_NULL();
 
462
        }
 
463
    }
 
464
    catch(const IceUtil::Exception& ex)
 
465
    {
 
466
        throwException(ex TSRMLS_CC);
 
467
        RETURN_NULL();
 
468
    }
 
469
}
 
470
 
 
471
#ifdef _WIN32
 
472
extern "C"
 
473
#endif
 
474
static zend_object_value
 
475
handleAlloc(zend_class_entry* ce TSRMLS_DC)
 
476
{
 
477
    zend_object_value result;
 
478
 
 
479
    Wrapper<Ice::PropertiesPtr>* obj = Wrapper<Ice::PropertiesPtr>::create(ce TSRMLS_CC);
 
480
    assert(obj);
 
481
 
 
482
    result.handle = zend_objects_store_put(obj, 0, (zend_objects_free_object_storage_t)handleFreeStorage, 0 TSRMLS_CC);
 
483
    result.handlers = &_handlers;
 
484
 
 
485
    return result;
 
486
}
 
487
 
 
488
#ifdef _WIN32
 
489
extern "C"
 
490
#endif
 
491
static void
 
492
handleFreeStorage(void* p TSRMLS_DC)
 
493
{
 
494
    Wrapper<Ice::PropertiesPtr>* obj = static_cast<Wrapper<Ice::PropertiesPtr>*>(p);
 
495
    delete obj->ptr;
 
496
    zend_objects_free_object_storage(static_cast<zend_object*>(p) TSRMLS_CC);
 
497
}
 
498
 
 
499
#ifdef _WIN32
 
500
extern "C"
 
501
#endif
 
502
static zend_object_value
 
503
handleClone(zval* zv TSRMLS_DC)
 
504
{
 
505
    zend_object_value result;
 
506
    memset(&result, 0, sizeof(zend_object_value));
 
507
 
 
508
    Ice::PropertiesPtr p = Wrapper<Ice::PropertiesPtr>::value(zv TSRMLS_CC);
 
509
    assert(p);
 
510
 
 
511
    Ice::PropertiesPtr pclone = p->clone();
 
512
 
 
513
    zval* clone;
 
514
    MAKE_STD_ZVAL(clone);
 
515
    if(!createProperties(clone, pclone TSRMLS_CC))
 
516
    {
 
517
        return result;
 
518
    }
 
519
 
 
520
    //
 
521
    // We only need to return the new object's handle, so we must destroy the zval containing
 
522
    // a reference to the new object. We increment the object's reference count to ensure it
 
523
    // does not get destroyed.
 
524
    //
 
525
    result = clone->value.obj;
 
526
    Z_OBJ_HT_P(clone)->add_ref(clone TSRMLS_CC);
 
527
    zval_dtor(clone);
 
528
    efree(clone);
 
529
 
 
530
    return result;
 
531
}
 
532
 
 
533
ZEND_FUNCTION(Ice_createProperties)
 
534
{
 
535
    zval* arglist = 0;
 
536
    zval* defaultsObj = 0;
 
537
 
 
538
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("|a!O!"), &arglist, &defaultsObj,
 
539
                             propertiesClassEntry) == FAILURE)
 
540
    {
 
541
        RETURN_NULL();
 
542
    }
 
543
 
 
544
    Ice::StringSeq seq;
 
545
    if(arglist && !extractStringArray(arglist, seq TSRMLS_CC))
 
546
    {
 
547
        RETURN_NULL();
 
548
    }
 
549
 
 
550
    Ice::PropertiesPtr defaults;
 
551
    if(defaultsObj && !fetchProperties(defaultsObj, defaults TSRMLS_CC))
 
552
    {
 
553
        RETURN_NULL();
 
554
    }
 
555
 
 
556
    try
 
557
    {
 
558
        Ice::PropertiesPtr props;
 
559
        if(arglist || defaults)
 
560
        {
 
561
            props = Ice::createProperties(seq, defaults);
 
562
        }
 
563
        else
 
564
        {
 
565
            props = Ice::createProperties();
 
566
        }
 
567
 
 
568
        if(!createProperties(return_value, props TSRMLS_CC))
 
569
        {
 
570
            RETURN_NULL();
 
571
        }
 
572
 
 
573
        if(arglist && PZVAL_IS_REF(arglist))
 
574
        {
 
575
            zval_dtor(arglist);
 
576
            if(!createStringArray(arglist, seq TSRMLS_CC))
 
577
            {
 
578
                RETURN_NULL();
 
579
            }
 
580
        }
 
581
    }
 
582
    catch(const IceUtil::Exception& ex)
 
583
    {
 
584
        throwException(ex TSRMLS_CC);
 
585
        RETURN_NULL();
 
586
    }
 
587
}
 
588
 
 
589
//
 
590
// Predefined methods for Properties.
 
591
//
 
592
static function_entry _interfaceMethods[] =
 
593
{
 
594
    {0, 0, 0}
 
595
};
 
596
static function_entry _classMethods[] =
 
597
{
 
598
    ZEND_ME(Ice_Properties, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
 
599
    ZEND_ME(Ice_Properties, __toString, NULL, ZEND_ACC_PUBLIC)
 
600
    ZEND_ME(Ice_Properties, getProperty, NULL, ZEND_ACC_PUBLIC)
 
601
    ZEND_ME(Ice_Properties, getPropertyWithDefault, NULL, ZEND_ACC_PUBLIC)
 
602
    ZEND_ME(Ice_Properties, getPropertyAsInt, NULL, ZEND_ACC_PUBLIC)
 
603
    ZEND_ME(Ice_Properties, getPropertyAsIntWithDefault, NULL, ZEND_ACC_PUBLIC)
 
604
    ZEND_ME(Ice_Properties, getPropertyAsList, NULL, ZEND_ACC_PUBLIC)
 
605
    ZEND_ME(Ice_Properties, getPropertyAsListWithDefault, NULL, ZEND_ACC_PUBLIC)
 
606
    ZEND_ME(Ice_Properties, getPropertiesForPrefix, NULL, ZEND_ACC_PUBLIC)
 
607
    ZEND_ME(Ice_Properties, setProperty, NULL, ZEND_ACC_PUBLIC)
 
608
    ZEND_ME(Ice_Properties, getCommandLineOptions, NULL, ZEND_ACC_PUBLIC)
 
609
    ZEND_ME(Ice_Properties, parseCommandLineOptions, NULL, ZEND_ACC_PUBLIC)
 
610
    ZEND_ME(Ice_Properties, parseIceCommandLineOptions, NULL, ZEND_ACC_PUBLIC)
 
611
    ZEND_ME(Ice_Properties, load, NULL, ZEND_ACC_PUBLIC)
 
612
    ZEND_ME(Ice_Properties, clone, NULL, ZEND_ACC_PUBLIC)
 
613
    {0, 0, 0}
 
614
};
 
615
 
 
616
bool
 
617
IcePHP::propertiesInit(TSRMLS_D)
 
618
{
 
619
    //
 
620
    // We register an interface and a class that implements the interface. This allows
 
621
    // applications to safely include the Slice-generated code for the type.
 
622
    //
 
623
 
 
624
    //
 
625
    // Register the Properties interface.
 
626
    //
 
627
    zend_class_entry ce;
 
628
#ifdef ICEPHP_USE_NAMESPACES
 
629
    INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("Properties"), _interfaceMethods);
 
630
#else
 
631
    INIT_CLASS_ENTRY(ce, "Ice_Properties", _interfaceMethods);
 
632
#endif
 
633
    zend_class_entry* interface = zend_register_internal_interface(&ce TSRMLS_CC);
 
634
 
 
635
    //
 
636
    // Register the Properties class.
 
637
    //
 
638
    INIT_CLASS_ENTRY(ce, "IcePHP_Properties", _classMethods);
 
639
    ce.create_object = handleAlloc;
 
640
    propertiesClassEntry = zend_register_internal_class(&ce TSRMLS_CC);
 
641
    memcpy(&_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 
642
    _handlers.clone_obj = handleClone;
 
643
    zend_class_implements(propertiesClassEntry TSRMLS_CC, 1, interface);
 
644
 
 
645
    return true;
 
646
}
 
647
 
 
648
bool
 
649
IcePHP::createProperties(zval* zv, const Ice::PropertiesPtr& p TSRMLS_DC)
 
650
{
 
651
    if(object_init_ex(zv, propertiesClassEntry) != SUCCESS)
 
652
    {
 
653
        runtimeError("unable to initialize properties object" TSRMLS_CC);
 
654
        return false;
 
655
    }
 
656
 
 
657
    Wrapper<Ice::PropertiesPtr>* obj = Wrapper<Ice::PropertiesPtr>::extract(zv TSRMLS_CC);
 
658
    assert(!obj->ptr);
 
659
    obj->ptr = new Ice::PropertiesPtr(p);
 
660
 
 
661
    return true;
 
662
}
 
663
 
 
664
bool
 
665
IcePHP::fetchProperties(zval* zv, Ice::PropertiesPtr& p TSRMLS_DC)
 
666
{
 
667
    if(!ZVAL_IS_NULL(zv))
 
668
    {
 
669
        if(Z_TYPE_P(zv) != IS_OBJECT || Z_OBJCE_P(zv) != propertiesClassEntry)
 
670
        {
 
671
            invalidArgument("value is not a properties object" TSRMLS_CC);
 
672
            return false;
 
673
        }
 
674
        p = Wrapper<Ice::PropertiesPtr>::value(zv TSRMLS_CC);
 
675
        if(!p)
 
676
        {
 
677
            runtimeError("unable to retrieve properties object from object store" TSRMLS_CC);
 
678
            return false;
 
679
        }
 
680
    }
 
681
    return true;
 
682
}