diff --git a/.gitignore b/.gitignore index a1fdd76..c324cd0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ .DS_Store .vscode/ +composer.lock composer.phar /vendor/ -tests/data/ +/src/tests/data/ + + diff --git a/composer.json b/composer.json index b109282..64ec3e6 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,15 @@ }, "autoload": { "psr-4": { - "Fasim\\": "src/Fasim" + "Fasim\\Cache\\": "src/Fasim/Cache", + "Fasim\\Core\\": "src/Fasim/Core", + "Fasim\\Db\\": "src/Fasim/Db", + "Fasim\\Event\\": "src/Fasim/Event", + "Fasim\\Facades\\": "src/Fasim/Facades", + "Fasim\\Library\\": "src/Fasim/Library", + "Fasim\\Log\\": "src/Fasim/Log", + "Fasim\\Session\\": "src/Fasim/Session", + "Fasim\\Support\\": "src/Fasim/Cache" }, "files": [ "src/Fasim/Support/helpers.php" diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 855f4c1..0000000 --- a/composer.lock +++ /dev/null @@ -1,80 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "content-hash": "f8daf5c384a847d277acd7fa5c0ec170", - "packages": [ - { - "name": "twig/twig", - "version": "v1.33.2", - "source": { - "type": "git", - "url": "https://github.com/twigphp/Twig.git", - "reference": "dd6ca96227917e1e85b41c7c3cc6507b411e0927" - }, - "dist": { - "type": "zip", - "url": "https://files.phpcomposer.com/files/twigphp/Twig/dd6ca96227917e1e85b41c7c3cc6507b411e0927.zip", - "reference": "dd6ca96227917e1e85b41c7c3cc6507b411e0927", - "shasum": "" - }, - "require": { - "php": ">=5.2.7" - }, - "require-dev": { - "psr/container": "^1.0", - "symfony/debug": "~2.7", - "symfony/phpunit-bridge": "~3.3@dev" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.33-dev" - } - }, - "autoload": { - "psr-0": { - "Twig_": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" - }, - { - "name": "Armin Ronacher", - "email": "armin.ronacher@active-4.com", - "role": "Project Founder" - }, - { - "name": "Twig Team", - "homepage": "http://twig.sensiolabs.org/contributors", - "role": "Contributors" - } - ], - "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "http://twig.sensiolabs.org", - "keywords": [ - "templating" - ], - "time": "2017-04-20T17:39:48+00:00" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/src/Fasim/Core/Router.php b/src/Fasim/Core/Router.php index a9b355a..1631a0d 100644 --- a/src/Fasim/Core/Router.php +++ b/src/Fasim/Core/Router.php @@ -48,7 +48,10 @@ public function getMatchAction() { public function init() { //获取配置 - $this->modules = Cfg::get('modules'); + $this->modules = Cfg::get('modules', null); + if (!is_array($this->modules)) { + $this->modules = []; + } $wd = $this->getWebsiteDirectory(); $requestUri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; diff --git a/src/Fasim/Widget/Form.php b/src/Fasim/Widget/Form.php deleted file mode 100644 index 5be47b0..0000000 --- a/src/Fasim/Widget/Form.php +++ /dev/null @@ -1,938 +0,0 @@ -data; - } - if ($value === null ) { - if (is_array($key)) { - $this->data = $key; - } else if (is_string($key)) { - return isset($this->data[$key]) ? $this->data[$key] : null; - } else { - return null; - } - } else { - $this->data[$key] = $value; - } - return $this; - } - - public function action($url) { - $this->action = Form::getUrl($url); - return $this; - } - - public function method($method) { - $this->method = $method; - return $this; - } - - public function handle($callback=null) { - $this->hasError = false; - - foreach ($this->controls as $control) { - if ($control instanceof FormValue) { - $pk = 'n_'.str_replace('.', '_-_', $control->key); - $value = isset($_POST[$pk]) ? $_POST[$pk] : ''; - if (!$control->checkRules($value)) { - $this->hasError = true; - } - $di = strpos($control->key, '.'); - if ($di !== false) { - $keys = explode('.', $control->key); - $values = &$this->data; - for ($i = 0; $i < count($keys); $i++) { - $key = $keys[$i]; - if ($i == count($keys) - 1) { - $values[$key] = $value; - } else { - if (!isset($values[$key])) { - $values[$key] = []; - } - $values = &$values[$key]; - } - } - } else { - $this->data[$control->key] = $value; - } - } - } - if ($callback != null && is_callable($callback)) { - $errors = $callback($this->hasError, $this->data); - if (is_array($errors) && count($errors) > 0) { - $this->hasError = true; - foreach ($errors as $ek => $ev) { - $this->addError($ek, $ev); - } - } - } - return !$this->hasError; - } - - public function isSuccess() { - return !$this->hasError; - } - - public function addError($key, $errorWord) { - foreach ($this->controls as $control) { - if (isset($control->key) && $control->key == $key) { - $control->addCustomError($errorWord); - } - } - } - - protected function getValue($key, $values) { - $di = strpos($key, '.'); - - if ($di !== false) { - $nkey = substr($key, $di + 1); - $key = substr($key, 0, $di); - - if (isset($values[$key])) { - return $this->getValue($nkey, $values[$key]); - } - } - if (isset($values[$key])) { - return $values[$key]; - } - //not found - return null; - } - - public function build() { - $html = "
\n"; - - foreach ($keys as $key) { - if (strpos($key, '.') != false) { - $nkey = str_replace('.', '_-_', $key); - $html = str_replace('_'.$key.'"', '_'.$nkey.'"', $html); - } - - } - return $html; - } - - public static function getUrl($url) { - if (strlen($url) < 4 || substr($url, 0, 4) != 'http') { - $adminUrl = Config::baseUrl(); - if ($url{0} == '/') { - $url = substr($url, 0, 1); - } - $url = $adminUrl.$url; - } - return $url; - } - - public function add($control) { - $this->controls[] = $control; - return $this; - } - - public function get($key) { - foreach ($this->controls as $control) { - if ($control->key == $key) { - return $control; - } - } - return null; - } - - public static function newHidden($key='') { - return new FormHidden($key); - } - - public static function newText($key='') { - return new FormText($key); - } - - public static function newSelect($key='', $options=[]) { - return new FormSelect($key, $options); - } - - public static function newImage($key='') { - return new FormImage($key); - } - - public static function newImages($key='') { - return new FormImages($key); - } - - public static function newFile($key='') { - return new FormFile($key); - } - - public static function newFiles($key='') { - return new FormFiles($key); - } - - public static function newTextarea($key='') { - return new FormTextarea($key); - } - - public static function newRichText($key='') { - return new FormRichText($key); - } - - public static function newButton($name='') { - return new FormButton($name); - } - - public static function newHtml($html='') { - return new FormHtml($html); - } - - public static function newScript($html='') { - return new FormScript($html); - } - -} - -interface FormControl { - function render(); -} - -class FormHtml implements FormControl { - public $html = ''; - - public function __construct($html='') { - $this->html($html); - } - - public function html($html='') { - $this->html = $html; - return $this; - } - - public function render() { - return $this->html; - } -} - -class FormScript extends FormHtml { - public function render() { - $html = ''."\n"; - return $html; - } -} - -abstract class FormValue implements FormControl { - public $label = ''; - public $key = ''; - public $value = ''; - public $readonly = false; - - - public $rules = []; - - public $min = 0; - public $max = 10000; - - public $errorWord = ''; - public $errorType = ''; - - public function __construct($key='') { - $this->key($key); - } - - public function label($label) { - $this->label = $label; - return $this; - } - - public function key($key) { - $this->key = $key; - return $this; - } - - public function value($value) { - $this->value = $value; - return $this; - } - - public function readonly($readonly=true) { - $this->readonly = $readonly; - return $this; - } - - public function notEmpty() { - $this->rules[] = 'not_empty'; - return $this; - } - - public function integerValue() { - $this->rules[] = 'integer'; - return $this; - } - - public function numbericValue() { - $this->rules[] = 'numberic'; - return $this; - } - - public function urlValue() { - $this->rules[] = 'url'; - return $this; - } - - public function emailValue() { - $this->rules[] = 'email'; - return $this; - } - - public function min($min) { - $this->min = $min; - return $this; - } - - public function max($max) { - $this->max = $max; - return $this; - } - - public function addRule($rule) { - $this->rules[] = $rule; - return $this; - } - - public function getError() { - - if ($this->errorType == '') { - return ''; - } - if ($this->errorWord != '') { - return $this->errorWord; - } - switch ($this->errorType) { - case 'min': - return '长度必须大于'.$this->min; - case 'max': - return '长度必须小于'.$this->max; - case 'not_empty': - return '不能为空'; - case 'integer': - return '必须是整数'; - case 'numberic': - return '必须是数字'; - case 'url': - return '必须是网址'; - case 'email': - return '必须是Email'; - } - return '格式错误'; - } - - public function error($errorWord) { - $this->errorWord = $errorWord; - } - - public function addCustomError($errorWord) { - $this->errorType = 'custom'; - $this->errorWord = $errorWord; - } - - public function checkRules($value) { - if (strlen($value.'') < $this->min) { - $this->errorType = 'min'; - return false; - } - if (strlen($value.'') > $this->max) { - $this->errorType = 'max'; - return false; - } - foreach ($this->rules as $rule) { - $result = $this->checkRule($rule, $value); - if (!$result) { - $this->errorType = $rule; - return false; - } - } - $this->errorType = ''; - return true; - } - - public function checkRule($rule, $value) { - if ($rule == 'not_empty') { - if (empty($value)) { - return false; - } - } else if (!empty($value)){ - $p = $rule; - if ($rule == 'integer') { - $p = '/^\d+$/s'; - } else if ($rule == 'numberic') { - $p = '/^\d+\.?\d*$/s'; - } else if ($rule == 'email') { - return filter_var($value, FILTER_VALIDATE_EMAIL); - } else if ($rule == 'url') { - return filter_var($value, FILTER_VALIDATE_URL); - } - if (!preg_match($p, $value)) { - return false; - } - } - return true; - } -} - - -class FormButton implements FormControl { - public $name; - public $link = ''; - public $primary = false; - public function __construct($name='') { - $this->name = $name; - } - - public function name($name) { - $this->name = $name; - return $this; - } - - public function link($url) { - $this->primary = false; - $this->url = $url; - return $this; - } - public function primary() { - $this->primary = true; - return $this; - } - - public function render() { - if ($this->primary) { - return " \n"; - } else if ($this->url != '') { - $url = Form::getUrl($this->url); - return "{$this->name} \n"; - } - } - -} - -class FormHidden extends FormValue { - - public function render() { - return "key}\" value=\"{$this->value}\" /> \n"; - } - -} - -class FormGroup extends FormValue { - - public $remark = ''; - - public function remark($remark) { - $this->remark = $remark; - return $this; - } - - public function render() { - $error = $this->getError(); - $errorClass = $error == '' ? '' : ' error'; - $html = "').appendTo( li ).find('span'); - } - percentDiv.css('width', percentage * 100 + '%' ); - }); - function showError(fileId, msg) { - console.log(fileId); - var li = $('#'+fileId), errorDiv = li.find('p.error'); - if ( !errorDiv.length ) { - errorDiv = $('').appendTo( li ); - } - errorDiv.text(msg); - } - uploader.on('uploadSuccess', function( file, response ) { - //$( '#'+file.id ).addClass('upload-state-done'); - if (typeof response == 'object') { - if (response.error == 0) { - var value = $('#{$fileId}').val(); - if (value != '') { - value = value + ';' + response.url; - } else { - value = response.url; - } - $('#{$fileId}').val(value); - } else { - showError(file.id, response.message); - } - } else { - showError(file.id, '上传失败'); - } - }); - uploader.on('uploadError', function( file ) { - showError(file.id, '上传失败'); - }); - uploader.on('uploadComplete', function( file ) { - $( '#'+file.id ).find('.progress').remove(); - }); -}); - -EOT; - return $html; - } -} - -class FormImage extends FormImages { - public function renderInput() { - $this->maxCount(1); - return parent::renderInput(); - } -} - -class FormFiles extends FormGroup { - - public $maxCount = 6; - public $allowFiles = 'doc,docx,xls,xlsx,ppt,pptx,txt,rar,zip,7z,html,htm,mp3,mov,mp4,avi'; - - public function maxCount($maxCount) { - $this->maxCount = $maxCount; - } - - public function allowFiles($allowFiles) { - $this->allowFiles = $allowFiles; - } - - public function renderInput() { - $fileId = 'i_'.$this->key; - $html = "key}\" value=\"{$this->value}\" /> \n"; - $fileListId = 'fileList_'.$this->key; - $filePickerId = 'filePicker_'.$this->key; - $files = empty($this->value) ? [] : explode(';', $this->value); - $html .= '
').appendTo( li ).find('span'); - } - percentDiv.css('width', percentage * 100 + '%' ); - }); - function showError(fileId, msg) { - console.log(fileId); - var li = $('#'+fileId), errorDiv = li.find('p.error'); - if ( !errorDiv.length ) { - errorDiv = $('').appendTo( li ); - } - errorDiv.text(msg); - } - uploader.on('uploadSuccess', function( file, response ) { - //$( '#'+file.id ).addClass('upload-state-done'); - if (typeof response == 'object') { - if (response.error == 0) { - var value = $('#{$fileId}').val(); - var item = response.url + ',' + file.name; - if (value != '') { - value = value + ';' + item; - } else { - value = item; - } - $('#{$fileId}').val(value); - } else { - showError(file.id, response.message); - } - } else { - showError(file.id, '上传失败'); - } - }); - uploader.on('uploadError', function( file ) { - showError(file.id, '上传失败'); - }); - uploader.on('uploadComplete', function( file ) { - $( '#'+file.id ).find('.progress').remove(); - }); -}); - -EOT; - return $html; - } -} - -class FormFile extends FormFiles { - public function renderInput() { - $this->maxCount(1); - return parent::renderInput(); - } -} - -class FormValueStyle extends FormGroup { - public $classStyle = 'input-xlarge'; - public $styles = []; - - public function mini() { - $this->classStyle = 'input-small'; - return $this; - } - - public function small() { - $this->classStyle = 'input-small'; - return $this; - } - - public function medium() { - $this->classStyle = 'input-medium'; - return $this; - } - - public function large() { - $this->classStyle = 'input-large'; - return $this; - } - - public function xLarge() { - $this->classStyle = 'input-xlarge'; - return $this; - } - - public function xxLarge() { - $this->classStyle = 'input-xxlarge'; - return $this; - } - - public function getStyle() { - $style = ''; - if (!empty($this->styles)) { - $style = ' style="'; - foreach ($this->styles as $k => $v) { - $style .= "$k:$v;"; - } - $style .= '"'; - } - return $style; - } - - public function width($width) { - $this->styles['width'] = $width + 'px'; - return $this; - } - - public function height($height) { - $this->styles['height'] = $height + 'px'; - return $this; - } - public function style($name, $value) { - $this->styles[$name] = $value; - return $this; - } -} - -class FormText extends FormValueStyle { - public $placeholder = ''; - - public function placeholder($placeholder) { - $this->placeholder = $placeholder; - return $this; - } - - public function renderInput() { - $style = $this->getStyle(); - $readonly = $this->readonly ? ' readonly="readonly"' : ''; - return "key}\" type=\"text\" name=\"n_{$this->key}\" placeholder=\"{$this->placeholder}\" value=\"{$this->value}\" class=\"{$this->classStyle}\"{$style}{$readonly} /> \n"; - } - - - -} - -class FormTextarea extends FormText { - public function renderInput() { - $style = $this->getStyle(); - $readonly = $this->readonly ? ' readonly="readonly"' : ''; - return " \n"; - } -} - -class FormRichText extends FormTextarea { - public function renderInput() { - if (!isset($this->styles['width'])) { - $this->style('width', '100%'); - } - if (!isset($this->styles['height'])) { - $this->style('height', '500px'); - } - $html = parent::renderInput(); - $html .= <<
{$field->name} | \n"; - } - if (count($this->operations) > 0) { - $list .= "操作 | \n"; - } - $list .= '
---|---|
\n" . $field->render() . " \n | ".$nl; - } - if (count($this->operations) > 0) { - $list .= "\n"; - for ($oi = 0; $oi < count($this->operations); $oi++) { - $opt = $this->operations[$oi]; - $opt->data = $row; - - if ($oi > 0) { - $list .= " | "; - } - $list .= $opt->render().$nl;; - } - $list .= " | \n"; - } - $list .= '