Skip to content

Commit

Permalink
Merge pull request #34
Browse files Browse the repository at this point in the history
Next set of bug fixes and improvements
  • Loading branch information
leonardosahon authored Jan 10, 2024
2 parents 6ed41aa + 715e9d4 commit 0573866
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
27 changes: 26 additions & 1 deletion src/BobDBuilder/Cmd/Traits/Make/AutoDeploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,44 @@ public function ad_default_files(string $pattern, string $domain_dir): void
{
$uuid = Gen::uuid(32);

// domain foundation file
file_put_contents(
$domain_dir . $this->plug->s . "foundation.php",
<<<FILE
<?php
use BrickLayer\Lay\Core\LayConfig;
LayConfig::set_cors(
[
"https://github.com",
],
fun: function () {
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Headers: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
}
);
FILE
);

// root index.php
file_put_contents(
$domain_dir . $this->plug->s . "index.php",
<<<FILE
<?php
use BrickLayer\Lay\Libs\LayCron;
use BrickLayer\Lay\Core\Exception;
const SAFE_TO_INIT_LAY = true;
include_once __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "foundation.php";
include_once "foundation.php";
// Replace [PRIMARY_DOMAIN] with your actual primary domain.
// Create a subdomain entry on your dns.
// Finally paste the link below to github or your CI platform
// Finally, paste the link below to github or your CI platform
// https://$pattern.[PRIMARY_DOMAIN]/$uuid
// As you can see, we recommend using a subdomain as your webhook url.
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Traits/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ public function dont_use_objects(): self
return $this->switch("use_objects", false);
}

public function use_domain_as_sub(): self
{
return $this->switch("use_domain_as_sub", true);
}

/**
* Prevents the data sent through the ViewHandler of a specific domain from being cached.
* This only takes effect in development environment, if Lay detects the server is in production, it'll cache by default
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Traits/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ private static function initialize() : self {
# Used by the Domain module to instruct the handler to cache all the listed domains in a session or cookie,
# depending on the value sent by dev
"cache_domains" => $options['switch']['cache_domains'] ?? true,
# If true, when linking to a domain using the Anchor tag class, on production server;
# example.com/blog will be converted to
# blog.example.com
"use_domain_as_sub" => $options['switch']['use_domain_as_sub'] ?? false,
# Internal option set by lay to tell dev that the /web/domain/ folder is where html is being served from
"using_domain" => $options['header']['using_domain'] ?? null,
# Internal option set by lay to tell dev that the /web/ folder is where html is being served from
"using_web" => $options['header']['using_web'] ?? null,
"use_domain_file" => null, // this is updated when webroot is created after first class is init
"name" => [
Expand Down
25 changes: 17 additions & 8 deletions src/Core/View/Tags/Anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ final class Anchor {

use Standard;

public function href(?string $link = "", ?string $domain_id = null) : self {
public function href(?string $link = "", ?string $domain_id = null, ?bool $use_subdomain = null) : self {
$dom = DomainResource::get()->domain;
$link = is_null($link) ? '' : $link;
$link = ltrim($link, "/");
$use_subdomain = $use_subdomain !== null ? $use_subdomain : LayConfig::new()->use_domain_as_sub();

$base = LayConfig::site_data();
$base_full = $dom->domain_uri;
Expand All @@ -33,17 +34,25 @@ public function href(?string $link = "", ?string $domain_id = null) : self {

$same_domain = $domain_id == $dom->domain_id;

if(!$same_domain && $dom->domain_type != DomainType::SUB) {
if(!$same_domain) {
$pattern = $pattern == "*" ? "" : $pattern;
$base_full = explode($dom->pattern . "/", $base_full . $pattern, 2)[0];
}

$base_full = rtrim($base_full, "/") . "/";
if($dom->domain_type != DomainType::SUB) {
$base_full = explode($dom->pattern . "/", $base_full . $pattern, 2)[0];

if($use_subdomain && !empty($pattern) && LayConfig::$ENV_IS_PROD)
$base_full = $base->proto . $pattern . "." . $base->domain_no_proto;
}
else {
$x = explode(".", $base->domain_no_proto, 2);
$base_full = $base->proto . end($x);

if(!$same_domain && $dom->domain_type == DomainType::SUB) {
$x = explode(".", $base->domain_no_proto, 2);
$base_full = $base->proto . end($x) . "/";
if($use_subdomain && !empty($pattern))
$base_full = $base->proto . $pattern . "." . end($x);
}
}

$base_full = rtrim($base_full, "/") . "/";
}

if(str_starts_with($link, "#"))
Expand Down
3 changes: 1 addition & 2 deletions src/Core/View/ViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use JetBrains\PhpStorm\ExpectedValues;
use JetBrains\PhpStorm\NoReturn;

// TODO: Find a way to cache views
final class ViewBuilder
{
use IsSingleton;
Expand Down Expand Up @@ -52,7 +51,7 @@ public function init_start(): self

if (!self::$href_set) {
self::$href_set = true;
$this->local("href", fn(?string $href = "", ?string $domain_id = null) => Anchor::new()->href($href, $domain_id)->get_href());
$this->local("href", fn(?string $href = "", ?string $domain_id = null, ?bool $use_subdomain = null) => Anchor::new()->href($href, $domain_id, $use_subdomain)->get_href());
}

return $this;
Expand Down
3 changes: 2 additions & 1 deletion src/Libs/LayMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
declare(strict_types=1);
namespace BrickLayer\Lay\Libs;

use BrickLayer\Lay\Core\View\DomainResource;
use JetBrains\PhpStorm\ArrayShape;
use JetBrains\PhpStorm\ExpectedValues;
use BrickLayer\Lay\Core\LayConfig;
Expand Down Expand Up @@ -267,7 +268,7 @@ final public function queue() : ?bool {

public function email_template(string $message) : string {
$data = LayConfig::site_data();
$logo = $data->img->logo;
$logo = DomainResource::get()->shared->img_default->logo;
$company_name = $data->name->short;
$copyright = $data->copy;
$text_color = "#000000";
Expand Down

0 comments on commit 0573866

Please sign in to comment.