Skip to content

Commit fdce442

Browse files
committed
rename ManaPHP to framework
0 parents  commit fdce442

File tree

555 files changed

+42732
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

555 files changed

+42732
-0
lines changed

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Autodetect text files
2+
* text=auto
3+
4+
# Ignore all test and documentation for archive
5+
/.gitattributes export-ignore
6+
/composer.lock export-ignore

.phpstorm.meta.php

+234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
<?php
2+
// This file is not a CODE, it makes no sense and won't run or validate
3+
// Its AST serves IDE as DATA source to make advanced type inference decisions.
4+
5+
namespace PHPSTORM_META {
6+
7+
use ManaPHP\ConfigInterface;
8+
9+
exitPoint(\abort());
10+
11+
override(\ManaPHP\Di\ContainerInterface::get(), map(['' => '@']));
12+
override(\container(), map(['' => '@']));
13+
14+
override(\ManaPHP\Di\ContainerInterface::make(), map(['' => '@']));
15+
16+
registerArgumentsSet(
17+
'eventManager',
18+
'httpServer:start',
19+
'httpServer:masterStart', 'httpServer:managerStart', 'httpServer:workerStart',
20+
'request:begin', 'request:end',
21+
'request:authorize', 'request:authenticate',
22+
'request:validate', 'request:ready',
23+
'request:invoking', 'request:invoked',
24+
'response:stringify',
25+
'request:responding', 'request:responded',
26+
'model:creating', 'model:created', 'model:saving', 'model:saved',
27+
'model:updating', 'model:updated', 'model:deleting', 'model:deleted',
28+
'db:connecting', 'db:connected', 'db:executing', 'db:executed', 'db:querying', 'db:queried', 'db:close',
29+
'db:begin', 'db:rollback', 'db:commit',
30+
'mailer:sending', 'mailer:sent',
31+
'redis:connecting', 'redis:connected', 'redis:calling', 'redis:called', 'redis:close',
32+
'httpClient:requesting', 'httpClient:requested',
33+
'httpClient:start', 'httpClient:complete', 'httpClient:error', 'httpClient:success',
34+
'wsClient:open', 'wsClient:close', 'wsClient:send', 'wsClient:recv', 'wsClient:message',
35+
'wsServer:open', 'wsServer:close', 'wsServer:start', 'wsServer:stop',
36+
'view:rendering', 'view:rendered',
37+
'renderer:rendering', 'renderer:rendered',
38+
'poolManager:push', 'poolManager:popping', 'poolManager:popped',
39+
'cache:miss', 'cache:hit',
40+
'wspServer:pushing', 'wspServer:pushed',
41+
'wspClient:push',
42+
'chatServer:come', 'chatServer:leave', 'chatServer:pushing', 'chatServer:pushed',
43+
'chatClient:push',
44+
'cli:invoking', 'cli:invoked',
45+
);
46+
expectedArguments(\ManaPHP\Event\ManagerInterface::attachEvent(), 0, argumentsSet('eventManager'));
47+
expectedArguments(\ManaPHP\Component::attachEvent(), 0, argumentsSet('eventManager'));
48+
49+
expectedArguments(\ManaPHP\Http\RequestInterface::getServer(), 0, array_keys($_SERVER)[$i]);
50+
expectedArguments(\ManaPHP\Http\RequestInterface::hasServer(), 0, array_keys($_SERVER)[$i]);
51+
52+
expectedArguments(
53+
\ManaPHP\Http\ResponseInterface::setJsonContent(), 0, ['code' => 0, 'message' => '', 'data' => []]
54+
);
55+
expectedReturnValues(
56+
\ManaPHP\Mvc\Controller::getAcl(),
57+
['*' => '@index', '*' => 'user', '*' => '*', 'list' => '@index', 'detail' => '@index',
58+
'create' => '@index', 'delete' => '@index', 'edit' => '@index']
59+
);
60+
61+
registerArgumentsSet('wspClientEndpoint', 'admin', 'user');
62+
expectedArguments(\ManaPHP\Ws\Pushing\ClientInterface::pushToId(), 2, argumentsSet('wspClientEndpoint'));
63+
expectedArguments(\ManaPHP\Ws\Pushing\ClientInterface::pushToName(), 2, argumentsSet('wspClientEndpoint'));
64+
expectedArguments(\ManaPHP\Ws\Pushing\ClientInterface::pushToRole(), 2, argumentsSet('wspClientEndpoint'));
65+
expectedArguments(\ManaPHP\Ws\Pushing\ClientInterface::pushToAll(), 1, argumentsSet('wspClientEndpoint'));
66+
expectedArguments(\ManaPHP\Ws\Pushing\ClientInterface::broadcast(), 1, argumentsSet('wspClientEndpoint'));
67+
68+
registerArgumentsSet(
69+
'validator_rules', [
70+
'required',
71+
'default',
72+
'bool',
73+
'int',
74+
'float',
75+
'string',
76+
'min' => 1,
77+
'max' => 2,
78+
'length' => '1-10',
79+
'minLength' => 1,
80+
'maxLength' => 1,
81+
'range' => '1-3',
82+
'regex' => '#^\d+$#',
83+
'alpha',
84+
'digit',
85+
'xdigit',
86+
'alnum',
87+
'lower',
88+
'upper',
89+
'trim',
90+
'email',
91+
'url',
92+
'ip',
93+
'date',
94+
'timestamp',
95+
'escape',
96+
'xss',
97+
'in' => [1, 2],
98+
'not_in' => [1, 2],
99+
'ext' => 'pdf,doc',
100+
'unique',
101+
'exists',
102+
'const',
103+
'account',
104+
'mobile',
105+
'safe',
106+
'readonly'
107+
]
108+
);
109+
expectedArguments(\input(), 1, argumentsSet('validator_rules'));
110+
expectedArguments(\ManaPHP\Validating\Validator::validateValue(), 2, argumentsSet('validator_rules'));
111+
expectedArguments(\ManaPHP\Validating\Validator::validateModel(), 2, argumentsSet('validator_rules'));
112+
113+
expectedArguments(
114+
\json_stringify(), 1,
115+
JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT
116+
| JSON_FORCE_OBJECT | JSON_PRESERVE_ZERO_FRACTION | JSON_PARTIAL_OUTPUT_ON_ERROR
117+
| JSON_UNESCAPED_LINE_TERMINATORS
118+
);
119+
120+
registerArgumentsSet('amqp_exchange_type', 'direct', 'topic', 'fanout', 'headers');
121+
expectedArguments(\ManaPHP\Amqp\Exchange::__construct(), 1, argumentsSet('amqp_exchange_type'));
122+
123+
registerArgumentsSet(
124+
'amqp_exchange_features',
125+
['passive' => false, 'durable' => true,
126+
'auto_delete' => false, 'internal' => false,
127+
'nowait' => false, 'arguments' => []]
128+
);
129+
expectedArguments(\ManaPHP\Amqp\Exchange::__construct(), 2, argumentsSet('amqp_exchange_features'));
130+
131+
registerArgumentsSet(
132+
'amqp_queue_features', [
133+
'passive' => false,
134+
'durable' => true,
135+
'exclusive' => false,
136+
'auto_delete' => false,
137+
'nowait' => false,
138+
'arguments' => [],
139+
]
140+
);
141+
expectedArguments(\ManaPHP\Amqp\Queue::__construct(), 1, argumentsSet('amqp_queue_features'));
142+
143+
function validator_rule()
144+
{
145+
return [
146+
'required',
147+
'bool',
148+
'int',
149+
'float',
150+
'string',
151+
'alpha',
152+
'digit',
153+
'xdigit',
154+
'alnum',
155+
'lower',
156+
'upper',
157+
'trim',
158+
'email',
159+
'url',
160+
'ip',
161+
'date',
162+
'timestamp',
163+
'escape',
164+
'xss',
165+
'unique',
166+
'exists',
167+
'const',
168+
'account',
169+
'mobile',
170+
'safe',
171+
'readonly',
172+
'default' => '',
173+
'min' => 0,
174+
'max' => 1,
175+
'range' => '0-1',
176+
'length' => '0-1',
177+
'minLength' => 1,
178+
'maxLength' => 1,
179+
'regex' => '#^\d+#',
180+
'in' => '1,2',
181+
'not_in' => '1,2',
182+
'ext' => 'jpg,jpeg',
183+
];
184+
}
185+
186+
registerArgumentsSet('manaphp_config', 'id', 'name', 'env', 'debug', 'params');
187+
expectedArguments(\ManaPHP\ConfigInterface::get(), 0, argumentsSet('manaphp_config'));
188+
expectedArguments(\ManaPHP\ConfigInterface::has(), 0, argumentsSet('manaphp_config'));
189+
expectedArguments(\ManaPHP\ConfigInterface::set(), 0, argumentsSet('manaphp_config'));
190+
}
191+
192+
/**
193+
* @xglobal $view ManaPHP\Mvc\ViewInterface
194+
*/
195+
/**
196+
* @var \ManaPHP\Mvc\ViewInterface $view
197+
* @var \ManaPHP\Html\RendererInterface $renderer
198+
*/
199+
$view = null;
200+
unset($view, $renderer);
201+
202+
class_exists('\Elasticsearch\Client') || class_alias('\stdClass', '\Elasticsearch\Client');
203+
204+
function model_fields($model)
205+
{
206+
return array_keys(get_object_vars($model));
207+
}
208+
209+
function model_field($model)
210+
{
211+
return key(get_object_vars($model));
212+
}
213+
214+
function model_var($model)
215+
{
216+
return get_object_vars($model);
217+
}
218+
219+
namespace ManaPHP\Data {
220+
class RedisCacheInterface extends \Redis implements RedisInterface
221+
{
222+
223+
}
224+
225+
class RedisDbInterface extends \Redis implements RedisInterface
226+
{
227+
228+
}
229+
230+
class RedisBrokerInterface extends \Redis implements RedisInterface
231+
{
232+
233+
}
234+
}

Alias.php

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ManaPHP;
5+
6+
use ManaPHP\Exception\InvalidArgumentException;
7+
use ManaPHP\Exception\MisuseException;
8+
9+
class Alias extends Component implements AliasInterface
10+
{
11+
protected array $aliases = ['@manaphp' => __DIR__];
12+
13+
public function set(string $name, string $path): string
14+
{
15+
if ($name[0] !== '@') {
16+
throw new MisuseException(['`:name` must start with `@`', 'name' => $name]);
17+
}
18+
19+
if ($path === '') {
20+
$this->aliases[$name] = $path;
21+
} elseif ($path[0] !== '@') {
22+
if (DIRECTORY_SEPARATOR === '/' || str_starts_with($name, '@ns.')) {
23+
$this->aliases[$name] = $path;
24+
} else {
25+
$this->aliases[$name] = strtr($path, '\\', '/');
26+
}
27+
} else {
28+
$this->aliases[$name] = $this->resolve($path);
29+
}
30+
31+
return $this->aliases[$name];
32+
}
33+
34+
public function get(string $name): ?string
35+
{
36+
if ($name[0] !== '@') {
37+
throw new MisuseException(['`:name` must start with `@`', 'name' => $name]);
38+
}
39+
40+
return $this->aliases[$name] ?? null;
41+
}
42+
43+
public function has(string $name): bool
44+
{
45+
if ($name[0] !== '@') {
46+
throw new MisuseException(['`:name` must start with `@`', 'name' => $name]);
47+
}
48+
49+
return isset($this->aliases[$name]);
50+
}
51+
52+
public function resolve(string $path): string
53+
{
54+
if ($path[0] !== '@') {
55+
return DIRECTORY_SEPARATOR === '/' ? $path : strtr($path, '\\', '/');
56+
}
57+
58+
if (str_contains($path, '{') && preg_match_all('#{([^}]+)}#', $path, $matches)) {
59+
foreach ((array)$matches[1] as $k => $match) {
60+
if (is_numeric($match)) {
61+
$replaced = substr(bin2hex(random_bytes($match / 2 + 1)), 0, $match);
62+
} else {
63+
$ts = $ts ?? time();
64+
$replaced = date($match, $ts);
65+
}
66+
67+
$path = str_replace($matches[0][$k], $replaced, $path);
68+
}
69+
}
70+
71+
if (DIRECTORY_SEPARATOR === '\\') {
72+
$path = strtr($path, '\\', '/');
73+
}
74+
75+
if (($pos = strpos($path, '/')) === false) {
76+
if (!isset($this->aliases[$path])) {
77+
throw new InvalidArgumentException(['`:alias` is not exists', 'alias' => $path]);
78+
}
79+
return $this->aliases[$path];
80+
}
81+
82+
$alias = substr($path, 0, $pos);
83+
84+
if (!isset($this->aliases[$alias])) {
85+
throw new InvalidArgumentException(['`%s` is not exists for `%s`', $alias, $path]);
86+
}
87+
88+
return $this->aliases[$alias] . substr($path, $pos);
89+
}
90+
}

AliasInterface.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ManaPHP;
5+
6+
interface AliasInterface
7+
{
8+
public function set(string $name, string $path): string;
9+
10+
public function get(string $name): ?string;
11+
12+
public function has(string $name): bool;
13+
14+
public function resolve(string $path): string;
15+
}

Amqp/Binding.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ManaPHP\Amqp;
5+
6+
class Binding
7+
{
8+
public string|Queue $queue;
9+
public string|Exchange $exchange;
10+
public string $binding_key;
11+
public array $arguments;
12+
13+
public function __construct(string|Queue $queue, string|Exchange $exchange, string $binding_key,
14+
array $arguments = []
15+
) {
16+
$this->queue = $queue;
17+
$this->exchange = $exchange;
18+
$this->binding_key = $binding_key;
19+
$this->arguments = $arguments;
20+
}
21+
}

Amqp/ChannelException.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ManaPHP\Amqp;
5+
6+
class ChannelException extends Exception
7+
{
8+
9+
}

0 commit comments

Comments
 (0)