55 lines
1.1 KiB
Text
55 lines
1.1 KiB
Text
|
|
--TEST--
|
||
|
|
Context: set/get/has and magic property access for plugin data storage
|
||
|
|
--FILE--
|
||
|
|
<?php
|
||
|
|
require '/var/www/app/context.php';
|
||
|
|
|
||
|
|
$templates = new Templates(base: '/tmp/b.php', page: '/tmp/p.php', list: '/tmp/l.php');
|
||
|
|
$ctx = new Context(
|
||
|
|
contentDir: '/tmp/content',
|
||
|
|
templates: $templates,
|
||
|
|
requestPath: 'blog/post',
|
||
|
|
hasTrailingSlash: true
|
||
|
|
);
|
||
|
|
|
||
|
|
// Public readonly properties
|
||
|
|
echo $ctx->requestPath . "\n";
|
||
|
|
echo $ctx->contentDir . "\n";
|
||
|
|
echo ($ctx->hasTrailingSlash ? 'true' : 'false') . "\n";
|
||
|
|
|
||
|
|
// set/get/has
|
||
|
|
$ctx->set('langPrefix', '/fr');
|
||
|
|
echo $ctx->get('langPrefix') . "\n";
|
||
|
|
echo ($ctx->has('langPrefix') ? 'yes' : 'no') . "\n";
|
||
|
|
echo ($ctx->has('missing') ? 'yes' : 'no') . "\n";
|
||
|
|
|
||
|
|
// get with default
|
||
|
|
echo $ctx->get('nope', 'fallback') . "\n";
|
||
|
|
|
||
|
|
// Magic __get / __set
|
||
|
|
$ctx->customKey = 'magic-value';
|
||
|
|
echo $ctx->customKey . "\n";
|
||
|
|
|
||
|
|
// Magic __get for undefined key returns null
|
||
|
|
echo ($ctx->undefined ?? 'null') . "\n";
|
||
|
|
|
||
|
|
// set and magic access are the same store
|
||
|
|
$ctx->set('shared', 'data');
|
||
|
|
echo $ctx->shared . "\n";
|
||
|
|
|
||
|
|
$ctx->magic2 = 'x';
|
||
|
|
echo $ctx->get('magic2') . "\n";
|
||
|
|
?>
|
||
|
|
--EXPECT--
|
||
|
|
blog/post
|
||
|
|
/tmp/content
|
||
|
|
true
|
||
|
|
/fr
|
||
|
|
yes
|
||
|
|
no
|
||
|
|
fallback
|
||
|
|
magic-value
|
||
|
|
null
|
||
|
|
data
|
||
|
|
x
|