Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	deft.php
  • Loading branch information
AlexanderGW committed Jul 2, 2020
2 parents 580a36d + 7699749 commit 66a3d3f
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 65 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "alexandergw/deft",
"type": "project",
"type": "deft-kernel",
"require": {
"ext-fileinfo": "*",
"ext-gd": "*",
"ext-json": "*"
"ext-json": "*",
"php": ">=7.3"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
Expand Down
22 changes: 4 additions & 18 deletions config/deft.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@

/**
* File: config/deft.php
* Date: 2020-04-21 21:44:09
* Auto-generated configuration by the Deft Framework
*/

return array(
'capture_hash' => 'b1049d593d520d138adfb69eeb9cde06',
'config_format' => 'php',
'debug' => 0,
'dir_lib' => 'lib',
'dir_plugin' => 'plugin',
'dir_public' => 'public',
'dir_public_asset' => 'asset',
'dir_tmp' => 'tmp',
'filesystem.type' => 'local',
'format' => 'php',
'plugins' => array(
0 => 'example',
1 => 'test'
),
'secret' => 'E+o;6y9J!.>}tMHr(d#5_vmGVTD3@ZR<hQ,{7f]K^1z8&j0UAkBueqNsPlXg*Ca$c4[%ixw|O2IY=~FbSp)LW?:n-',
'token_hash' => '5140c5a01a70e0991836ca1d8805527c',
'token_timeout' => 2592000,
'url_separator' => '/'
'example',
'test',
'debug'
)
);
2 changes: 1 addition & 1 deletion config/locale/es-es.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'locale' => 'es-ES'
),
array(
'Environment settings' => 'La configuración del entorno',
'User environment' => 'La configuración del entorno',
'Hello' => 'Hola',
'Language' => 'Idioma',
'Welcome' => 'Bienvenido'
Expand Down
23 changes: 18 additions & 5 deletions deft.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* Class Deft
*/
class Deft {
const VERSION = '0.7';
const VERSION = '0.8';

const PLUGIN_LOADED = 2;
const PLUGIN_EXISTS = 1;
Expand Down Expand Up @@ -95,7 +95,7 @@ class Deft {
*
* @param array $args
*/
static function init ($config) {
static function init ($config = []) {
if (self::$initialized || !is_array($config)) {
return null;
}
Expand Down Expand Up @@ -966,6 +966,19 @@ public function getArg ($arg = null, $filter = null, $default = NULL, $seperator

return $return;
}

/**
* @param $key
*
* @return mixed|null
*/
public function __get($key) {
return $this->getArg($key);
}

// public function __set($key, $value) {
// return $this->setArg($key, $value);
// }
}

/**
Expand All @@ -980,9 +993,9 @@ function __ ( /*polymorphic*/) {
$args = func_get_args();
$phrase = array_shift($args);

// if (\Deft::locale()->isDefault() === false) {
// $phrase = \Deft::locale()->getPhrase($phrase);
// }
if (\Deft::locale()->isDefault() === false) {
$phrase = \Deft::locale()->getPhrase($phrase);
}

if (count($args)) {
$phrase = vsprintf($phrase, $args);
Expand Down
12 changes: 9 additions & 3 deletions lib/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ public static function wasRouted() {
* Cache management
*/
public static function cacheManagement() {
$data = \Deft::route()->current()->data ?: [];
$actions = [
'clear'
];
$action = \Deft::route()->current()->data['action'];
$action = $data['action'];

if (!in_array($action, $actions))
\Deft::log()->error(__('Unknown cache management action "%1$s"', $action));
Expand All @@ -124,12 +125,12 @@ public static function cacheManagement() {
'all',
'public'
];
$task = \Deft::route()->current()->data['task'];
$task = array_key_exists('task', $data) ? $data['task'] : 'all';

if (!in_array($task, $tasks))
return \Deft::log()->error(__('Unknown cache management action "clear" task "%1$s"', $task));

\Deft::log()->status(__('Started clearing "%1$s" caches', $task));
___('Started clearing "%1$s" caches', $task);

$fs = \Deft::filesystem();

Expand All @@ -145,6 +146,11 @@ public static function cacheManagement() {
self::logLastEventCall('cliCacheClearPublic');
}

if ($task === 'storage' || $task === 'all') {
\Deft::event()->exec('cliCacheClearStorage');
self::logLastEventCall('cliCacheClearStorage');
}

if ($task === 'all') {
\Deft::event()->exec('cliCacheClearAll');
self::logLastEventCall('cliCacheClearAll');
Expand Down
1 change: 1 addition & 0 deletions lib/fIlesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Deft\Lib;

// TODO: Switch to filesystem.local

class Filesystem extends \Deft_Concrete {

Expand Down
9 changes: 4 additions & 5 deletions lib/locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function init () {
}
if (!$string) {
$query = (array)\Deft::route()->current('data');
if (array_key_exists('data', $query))
if (array_key_exists('locale', $query))
$string['locale'];
}
if (!$string) {
Expand Down Expand Up @@ -144,16 +144,15 @@ public static function init () {
*/
public static function negotiate ($locale = null) {
if (is_string($locale) and (strlen($locale) == 2 or strlen($locale) == 5)) {
$config = \Deft::config();
$locales = $config->get('locales', array());
$locales = \Deft::config()->get('locales', []);

if (strlen($locale) == 5) {
if (strlen($locale) === 5) {
if (in_array($locale, $locales)) {
return $locale;
}
$locale = substr($locale, 0, 2);
}
if (strlen($locale) == 2 and in_array($locale, $locales)) {
if (strlen($locale) === 2 and in_array($locale, $locales)) {
return $locale;
}
}
Expand Down
12 changes: 12 additions & 0 deletions lib/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ class Response extends \Deft_Concrete {
// parent::__construct($this->args, $class);
// }

/**
* @param null $buffer
*
* @return string
*/
public function type($buffer = NULL) {
if (is_null($buffer))
return $this->getArg('type');
$this->setArg('type', $buffer);
return TRUE;
}

/**
* @param null $buffer
*
Expand Down
2 changes: 2 additions & 0 deletions lib/response/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use Deft\Lib\Response;

class Http extends Response {
protected $cookies = [];
protected $headers = [];

/**
* @param null $uri
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"scripts": {
"up": "php -S localhost:8000 -t ./public",
"test": "./vendor/bin/phpunit --configuration ./phpunit.xml --verbose",
"debug": "./vendor/bin/phpunit --debug --configuration ./phpunit.xml"
"debug": "./vendor/bin/phpunit --debug --configuration ./phpunit.xml",
"postinstall": "grunt"
},
"repository": {
"type": "git",
Expand Down
2 changes: 2 additions & 0 deletions plugin/debug/asset/debug.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ section.deft-debug {
div.detail {
display: block;
overflow-x: scroll;
padding: .75em;
font-family: monospace;
}
}

Expand Down
27 changes: 20 additions & 7 deletions plugin/debug/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,26 @@ class Debug extends Plugin {
private static $hash;

public static function init () {
\Deft::route()->add('debug', 'debug', null, '\Deft\Plugin\Debug::returnSetting');
\Deft::route()->add('debug.request', 'debug/request/[hash]', array(
\Deft::route()->http('debug', 'debug', null, '\Deft\Plugin\Debug::returnSetting');
\Deft::route()->http('debug.request', 'debug/request/[hash]', array(
'hash' => '[0-9a-z]{32}'
), '\Deft\Plugin\Debug::returnRequest');

\Deft::event()->set('ready', '\Deft\Plugin\Debug::setResponseAssets');

\Deft::event()->set('cliCacheClearStorage', function(){
$fs = \Deft::filesystem();
if ($fs->exists(DEFT_STORAGE_PATH . DS . 'debug')) {
if (!$fs->delete(DEFT_STORAGE_PATH . DS . 'debug', true)) {
\Deft::log()->warning(__('Failed to delete debug storage'));
}
}
});
}

public static function setResponseAssets() {
$res = \Deft::response();
if ($res->getArg('type') === 'http.html') {
if ($res->type === 'http.html') {
$hash = \Deft\Plugin\Debug::getHash();
$res->addScriptContent("var Deft = Deft || {}; Deft.debugHash = '{$hash}';");
$res->addScript('plugin/debug/asset/debug.js');
Expand Down Expand Up @@ -112,7 +121,7 @@ public static function returnRequest() {
// Set response output to JSON
\Deft::config()->set('response.type', 'http.json');

$content = file_get_contents(self::getPath() . DS . \Deft::route()->getParam('hash') . '.json');
$content = \Deft::filesystem()->read(self::getPath() . DS . \Deft::route()->getParam('hash') . '.json');

// Buffer the content
\Deft::response()->buffer($content);
Expand All @@ -125,9 +134,13 @@ public static function shutdown() {
}

public static function captureWriteJson() {
if (!is_dir(self::getPath()))
mkdir(self::getPath());
file_put_contents(self::getPath() . DS . self::getHash() . '.json', \Deft::capture('plugin.debug.template.json'));
$fs = \Deft::filesystem();

if ($fs->exists(self::getPath()) === false)
$fs->install(self::getPath());

if (!$fs->write(self::getPath() . DS . self::getHash() . '.json', \Deft::capture('plugin.debug.template.json')))
\Deft::log()->warning(__('Failed to write debug stack JSON to storage'));
}
}

Expand Down
55 changes: 51 additions & 4 deletions plugin/example/asset/scss/example.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
%font-root {
font-size: 12pt;
letter-spacing: .075rem;
line-height: 1.25;
}

$background-color: #3a3a3a;
Expand All @@ -12,9 +14,7 @@ body {
border: none;
box-sizing: border-box;
font-family: 'Raleway', sans-serif;
line-height: 1.25;
background-color: $background-color;
letter-spacing: .075rem;
text-align: initial;
@extend %font-root;
> main {
Expand All @@ -41,10 +41,55 @@ body {
}
}

.pad-l1 {
padding-left: 2em;
}

.grid {
font-size: 0;
letter-spacing: 0;
line-height: 1;
> div {
display: inline-block;
vertical-align: top;
@extend %font-root;
width: 100%;
&.col-9 {
width: 75%;
}
&.col-6 {
width: 50%;
}
&.col-3 {
width: 25%;
}
}
}

.logo {
box-sizing: border-box;
display: inline-block;
border: .25em solid #fff;
padding: 2em 1em 1em;
width: 172px;
height: 172px;
line-height: 1;
div:first-child {
font-size: 4em;
}
div:last-child {
text-align: center;
text-transform: uppercase;
font-weight: 700;
letter-spacing: .125em;
margin-top: 1.25em;
}
}

h1 {
margin: 0;
margin: 0 0 .5em 0;
padding: 0;
font-size: 4em;
font-size: 2.5em;
font-weight: 400;
}

Expand Down Expand Up @@ -164,6 +209,8 @@ p {
margin: 0;
&.cta {
background-color: #252525;
padding: 1em;
margin: 1em 0;
}
}

Expand Down
Loading

0 comments on commit 66a3d3f

Please sign in to comment.