Skip to content

Commit

Permalink
Merge pull request #175 from hydephp/v0.15.x-dev
Browse files Browse the repository at this point in the history
Refactor internal codebase by sorting traits into relevant namespaces
  • Loading branch information
caendesilva authored Apr 27, 2022
2 parents 4c2080b + 34754f2 commit e9ca247
Show file tree
Hide file tree
Showing 29 changed files with 220 additions and 183 deletions.
1 change: 1 addition & 0 deletions src/Actions/GeneratesTableOfContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework\Actions;

use Hyde\Framework\Contracts\ActionContract;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;
Expand Down
1 change: 1 addition & 0 deletions src/Actions/PublishesHomepageView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework\Actions;

use Hyde\Framework\Contracts\ActionContract;
use Hyde\Framework\Hyde;

class PublishesHomepageView implements ActionContract
Expand Down
1 change: 1 addition & 0 deletions src/Actions/PublishesHydeViews.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework\Actions;

use Hyde\Framework\Contracts\ActionContract;
use Hyde\Framework\Hyde;
use Illuminate\Support\Facades\File;

Expand Down
3 changes: 2 additions & 1 deletion src/Models/HasAuthor.php → src/Concerns/HasAuthor.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Hyde\Framework\Models;
namespace Hyde\Framework\Concerns;

use Hyde\Framework\Models\Author;
use Hyde\Framework\Services\AuthorService;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Hyde\Framework\Models;
namespace Hyde\Framework\Concerns;

use Hyde\Framework\Models\DateString;

trait HasDateString
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Hyde\Framework\Models;
namespace Hyde\Framework\Concerns;

use Hyde\Framework\Hyde;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Hyde\Framework\Models;
namespace Hyde\Framework\Concerns;

use Hyde\Framework\Models\Image;

trait HasFeaturedImage
{
Expand Down
3 changes: 2 additions & 1 deletion src/Models/HasMetadata.php → src/Concerns/HasMetadata.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace Hyde\Framework\Models;
namespace Hyde\Framework\Concerns;

use Hyde\Framework\Hyde;
use Hyde\Framework\Models\Metadata;
use JetBrains\PhpStorm\ArrayShape;

trait HasMetadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Hyde\Framework\Models;
namespace Hyde\Framework\Concerns;

use function config;
use Hyde\Framework\Actions\GeneratesTableOfContents;

/**
Expand Down
37 changes: 37 additions & 0 deletions src/Concerns/Internal/AssetManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Hyde\Framework\Concerns\Internal;

use function config;

/**
* AssetManager for the Hyde Facade.
*/
trait AssetManager
{
/**
* Return the Tailwind CDN if enabled.
*/
public static function tailwind(): string|false
{
return config('hyde.loadTailwindFromCDN')
? 'https://cdn.jsdelivr.net/gh/hydephp/[email protected]/dist/app.css'
: false;
}

/**
* Return the Hyde stylesheet.
*/
public static function styles(): string
{
return 'https://cdn.jsdelivr.net/gh/hydephp/[email protected]/dist/hyde.css';
}

/**
* Return the Hyde scripts.
*/
public static function scripts(): string
{
return 'https://cdn.jsdelivr.net/gh/hydephp/[email protected]/dist/hyde.js';
}
}
127 changes: 127 additions & 0 deletions src/Concerns/Internal/FileHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace Hyde\Framework\Concerns\Internal;

use function config;

/**
* General file helpers intended to be used through the Hyde Facade.
*/
trait FileHelpers
{
/**
* Get the subdirectory compiled documentation files are stored in.
*
* @return string
*/
public static function docsDirectory(): string
{
return trim(config('hyde.docsDirectory', 'docs'), '/\\');
}

/**
* Get the path to the frontpage for the documentation.
*
* @return string|false returns false if no frontpage is found
*/
public static function docsIndexPath(): string|false
{
if (file_exists(static::path('_docs/index.md'))) {
return static::docsDirectory().'/index.html';
}

if (file_exists(static::path('_docs/readme.md'))) {
return static::docsDirectory().'/readme.html';
}

return false;
}

/**
* Get an absolute file path from a supplied relative path.
*
* The function returns the fully qualified path to your site's root directory.
*
* You may also use the function to generate a fully qualified path to a given file
* relative to the project root directory when supplying the path argument.
*
* @param string $path
* @return string
*/
public static function path(string $path = ''): string
{
if (empty($path)) {
return getcwd();
}

$path = trim($path, '/\\');

return getcwd().DIRECTORY_SEPARATOR.$path;
}

/**
* Works similarly to the path() function, but returns a file in the Framework package.
*
* @param string $path
* @return string
*/
public static function vendorPath(string $path = ''): string
{
return static::path('vendor/hyde/framework/'.trim($path, '/\\'));
}

/**
* Inject the proper number of `../` before the links in Blade templates.
*
* @param string $destination the route to format
* @param string $current the current route
* @return string
*/
public static function relativePath(string $destination, string $current = ''): string
{
$nestCount = substr_count($current, '/');
$route = '';
if ($nestCount > 0) {
$route .= str_repeat('../', $nestCount);
}
$route .= $destination;

return $route;
}

/**
* Return a qualified URI path, if SITE_URL is set in .env, else return false.
*
* @param string|null $path optional relative path suffix. Omit to return base url.
* @return string|false
*/
public static function uriPath(?string $path = ''): string|false
{
if (config('hyde.site_url', false)) {
return rtrim(config('hyde.site_url'), '/').'/'.(trim($path, '/') ?? '');
}

return false;
}

/**
* Wrapper for the copy function, but allows choosing if files may be overwritten.
*
* @param string $from The source file path.
* @param string $to The destination file path.
* @param bool $force If true, existing files will be overwritten.
* @return bool|int Returns true|false on copy() success|failure, or an error code on failure
*/
public static function copy(string $from, string $to, bool $force = false): bool|int
{
if (! file_exists($from)) {
return 404;
}

if (file_exists($to) && ! $force) {
return 409;
}

return copy($from, $to);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Hyde\Framework\Actions\ServiceActions;
namespace Hyde\Framework\Concerns\Markdown;

use Hyde\Framework\Features;
use Hyde\Framework\Markdown;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Hyde\Framework\Actions\ServiceActions;
namespace Hyde\Framework\Concerns\Markdown;

use function config;

/**
* Global Markdown Feature Handler.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Hyde\Framework\Actions\ServiceActions;
namespace Hyde\Framework\Concerns\Markdown;

use function config;

trait HasTorchlightIntegration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Hyde\Framework\Actions;
namespace Hyde\Framework\Concerns;

use Exception;
use Hyde\Framework\Hyde;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Hyde\Framework\Models;
namespace Hyde\Framework\Contracts;

/**
* To ensure compatability with the Hyde Framework,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace Hyde\Framework;
namespace Hyde\Framework\Contracts;

use Hyde\Framework\Actions\ValidatesExistence;
use Hyde\Framework\Models\AbstractPage;
use Hyde\Framework\Concerns\ValidatesExistence;

/**
* Abstract base class for all page parsers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Hyde\Framework\Actions;
namespace Hyde\Framework\Contracts;

/**
* Interface ActionContract.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

namespace Hyde\Framework;

use Hyde\Framework\Models\AbstractPage;
namespace Hyde\Framework\Contracts;

interface PageParserContract
{
Expand Down
1 change: 1 addition & 0 deletions src/DocumentationPageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework;

use Hyde\Framework\Contracts\AbstractPageParser;
use Hyde\Framework\Models\DocumentationPage;
use Hyde\Framework\Services\MarkdownFileService;

Expand Down
Loading

0 comments on commit e9ca247

Please sign in to comment.