-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathphp_iterator.h
More file actions
111 lines (94 loc) · 2 KB
/
php_iterator.h
File metadata and controls
111 lines (94 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* PhpIterator.h
*
* Class to iterate over a JS\Object. This instance is constructed
* by the JSObject::getIterator() method.
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2025 Copernica BV
*/
/**
* Include guard
*/
#pragma once
/**
* Dependencies
*/
#include <phpcpp.h>
#include <v8.h>
#include <core.h>
/**
* Begin of namespace
*/
namespace JS {
/**
* Class definition
*/
class PhpIterator : public Php::Iterator
{
private:
/**
* The javascript core
* @var std::shared_ptr<Core>
*/
std::shared_ptr<Core> _core;
/**
* The underlying ecmascript object
* @var Stack<v8::Object>
*/
v8::Global<v8::Object> _object;
/**
* All properties in the object
* @var Stack<v8::Array>
*/
v8::Global<v8::Array> _keys;
/**
* Current position in the object
* @var uint32_t
*/
uint32_t _position = 0;
/**
* Number of valid keys
* @var uint32_t
*/
uint32_t _size = 0;
public:
/**
* Constructor
* @param base The base that PHP-CPP insists on
* @param core The javascript core
* @param object The object to iterate
*/
PhpIterator(Php::Base *base, const std::shared_ptr<Core> &core, const v8::Local<v8::Object> &object);
/**
* Destructor
*/
virtual ~PhpIterator();
/**
* Is the iterator still valid?
* @return is an element present at the current offset
*/
virtual bool valid() override;
/**
* Retrieve the current value
* @return value at current offset
*/
virtual Php::Value current() override;
/**
* Retrieve the current key
* @return the current key
*/
virtual Php::Value key() override;
/**
* Move ahead to the next item
*/
virtual void next() override;
/**
* Start over at the beginning
*/
virtual void rewind() override;
};
/**
* End of namespace
*/
}