php: views-classes added

This commit is contained in:
rivexe
2023-02-13 16:30:00 +03:00
parent bba6473b95
commit 6f69350183
4 changed files with 100 additions and 0 deletions

View File

@ -19,6 +19,7 @@
"psr-4": {
"OnlineEditorsExamplePhp\\" : "",
"OnlineEditorsExamplePhp\\Helpers\\" : "helpers/",
"OnlineEditorsExamplePhp\\Views\\" : "views/",
"Firebase\\JWT\\" : "lib/jwt/"
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace OnlineEditorsExamplePhp\Views;
final class DocEditorView extends View
{
public function __construct($tempName = "docEditor")
{
parent::__construct($tempName);
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace OnlineEditorsExamplePhp\Views;
final class IndexView extends View
{
public function __construct($tempName = "index")
{
parent::__construct($tempName);
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace OnlineEditorsExamplePhp\Views;
class View
{
private $template;
const TEMPNAMES = [
"index" => "index",
"docEditor" => "doceditor",
];
public function __construct($tempName)
{
$pathToTemplate = "./templates/".self::TEMPNAMES[$tempName].".tpl";
if (file_exists($pathToTemplate)) {
$this->template = file_get_contents($pathToTemplate);
} else {
$this->template = "";
}
}
public function parseTemplate($tagsValues = [])
{
$parsedTemplate = $this->template;
foreach ($tagsValues as $tag => $value) {
$parsedTemplate = str_replace($tag, $value, $parsedTemplate);
}
return $parsedTemplate;
}
}