Skip to content

Commit

Permalink
улучшена совместная работа с Laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Surkov committed Aug 28, 2021
1 parent e0af3b1 commit dd138ca
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 60 deletions.
9 changes: 1 addition & 8 deletions src/Core/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,7 @@ public function fetch($content)

protected function getTemplate()
{
return
'use function ' . __NAMESPACE__ . '\\app;
use function ' . __NAMESPACE__ . '\\asset;
use function ' . __NAMESPACE__ . '\\route;
use function ' . __NAMESPACE__ . '\\css;
use function ' . __NAMESPACE__ . '\\js;
?>' . $this->template;
return 'use function ' . __NAMESPACE__ . '\\app,asset,route,css,js,adminRoute,apiRoute;'.PHP_EOL.' ?>' . $this->template;
}

public function __toString()
Expand Down
102 changes: 58 additions & 44 deletions src/core_helpers.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace _DS;

use Dissonance\Core\Config;
Expand All @@ -18,7 +19,8 @@ function app($abstract = null, array $parameters = null)
}
return is_null($parameters) ? $core->get($abstract) : $core->make($abstract, $parameters);
}
if (! function_exists('config')) {

if (!function_exists('_DS\\config')) {
/**
* Get Config data
* @param string|null $key
Expand All @@ -29,15 +31,15 @@ function app($abstract = null, array $parameters = null)
function config(string $key = null, $default = null)
{
$config = app('config');
return is_null($key) ? $config : ($config->has($key)?$config->get($key):$default);
return is_null($key) ? $config : ($config->has($key) ? $config->get($key) : $default);
}
}

if (! function_exists('event')) {
if (!function_exists('_DS\\event')) {
/**
* Run event
*
* @param object $event
* @param object $event
*
* @return object $event
*/
Expand All @@ -46,14 +48,14 @@ function event(object $event)
return app('events')->dispatch($event);
}
}
if (! function_exists('route')) {
if (!function_exists('_DS\\route')) {

/**
* Generate the URL to a named route.
*
* @param array|string $name
* @param mixed $parameters
* @param bool $absolute
* @param array|string $name
* @param mixed $parameters
* @param bool $absolute
* @return string
*/
function route($name, $parameters = [], $absolute = true)
Expand All @@ -63,11 +65,7 @@ function route($name, $parameters = [], $absolute = true)
}






if (!function_exists('camel_case')) {
if (!function_exists('_DS\\camel_case')) {
/**
* Convert a value to camel case.
*
Expand All @@ -82,7 +80,7 @@ function camel_case($value)
}
}

if (!function_exists('class_basename')) {
if (!function_exists('_DS\\class_basename')) {
/**
* Get the class "basename" of the given object / class.
*
Expand All @@ -97,7 +95,7 @@ function class_basename($class)
}
}

if (!function_exists('collect')) {
if (!function_exists('_DS\\collect')) {
/**
* Create a collection from the given value.
*
Expand All @@ -110,7 +108,7 @@ function collect($value = null)
}
}

if (!function_exists('data_fill')) {
if (!function_exists('_DS\\data_fill')) {
/**
* Fill in data where it's missing.
*
Expand All @@ -125,7 +123,7 @@ function data_fill(&$target, $key, $value)
}
}

if (!function_exists('data_get')) {
if (!function_exists('_DS\\data_get')) {
/**
* Get an item from an array or object using "dot" notation.
*
Expand Down Expand Up @@ -172,7 +170,7 @@ function data_get($target, $key, $default = null)
}
}

if (!function_exists('data_set')) {
if (!function_exists('_DS\\data_set')) {
/**
* Set an item on an array or object using dot notation.
*
Expand Down Expand Up @@ -235,8 +233,7 @@ function data_set(&$target, $key, $value, $overwrite = true)
}



if (!function_exists('ends_with')) {
if (!function_exists('_DS\\ends_with')) {
/**
* Determine if a given string ends with a given substring.
*
Expand All @@ -252,7 +249,37 @@ function ends_with($haystack, $needles)
}
}

if (!function_exists('filled')) {

if (! function_exists('_DS\\blank')) {
/**
* Determine if the given value is "blank".
*
* @param mixed $value
* @return bool
*/
function blank($value)
{
if (is_null($value)) {
return true;
}

if (is_string($value)) {
return trim($value) === '';
}

if (is_numeric($value) || is_bool($value)) {
return false;
}

if ($value instanceof \Countable) {
return count($value) === 0;
}

return empty($value);
}
}

if (!function_exists('_DS\\filled')) {
/**
* Determine if a value is "filled".
*
Expand All @@ -266,13 +293,7 @@ function filled($value)
}








if (!function_exists('preg_replace_array')) {
if (!function_exists('_DS\\preg_replace_array')) {
/**
* Replace a given pattern with each value in the array in sequentially.
*
Expand All @@ -292,8 +313,7 @@ function preg_replace_array($pattern, array $replacements, $subject)
}



if (!function_exists('snake_case')) {
if (!function_exists('_DS\\snake_case')) {
/**
* Convert a string to snake case.
*
Expand All @@ -309,7 +329,7 @@ function snake_case($value, $delimiter = '_')
}
}

if (!function_exists('serialize64')) {
if (!function_exists('_DS\\serialize64')) {
/**
* Serialization with base64 encode
*
Expand All @@ -323,7 +343,7 @@ function serialize64($value)
}
}

if (!function_exists('unserialize64')) {
if (!function_exists('_DS\\unserialize64')) {
/**
* unserialization with base64 decode
*
Expand All @@ -340,13 +360,7 @@ function unserialize64(string $str, array $options = [])
}








//if (!function_exists('throw_if')) {
//if (!function_exists('_DS\\throw_if')) {
// /**
// * Throw the given exception if the given condition is true.
// *
Expand All @@ -367,7 +381,7 @@ function unserialize64(string $str, array $options = [])
// }
//}

//if (!function_exists('throw_unless')) {
//if (!function_exists('_DS\\throw_unless')) {
// /**
// * Throw the given exception unless the given condition is true.
// *
Expand All @@ -387,7 +401,7 @@ function unserialize64(string $str, array $options = [])
// }
//}

//if (!function_exists('title_case')) {
//if (!function_exists('_DS\\title_case')) {
// /**
// * Convert a value to title case.
// *
Expand All @@ -402,7 +416,7 @@ function unserialize64(string $str, array $options = [])
// }
//}

if (!function_exists('transform')) {
if (!function_exists('_DS\\transform')) {
/**
* Transform the given value if it is present.
*
Expand All @@ -425,7 +439,7 @@ function transform($value, callable $callback, $default = null)
}
}

if (!function_exists('value')) {
if (!function_exists('_DS\\value')) {
/**
* Return the default value of the given value.
*
Expand All @@ -439,7 +453,7 @@ function value($value)
}


if (!function_exists('with')) {
if (!function_exists('_DS\\with')) {
/**
* Return the given value, optionally passed through the given callback.
*
Expand Down
20 changes: 12 additions & 8 deletions src/http_kernel_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;

function response(int $code = 200,\Throwable $exception = null):ResponseInterface
{
return app(HttpKernelInterface::class)->response($code, $exception);
if (!function_exists('_DS\\response')) {
function response(int $code = 200, \Throwable $exception = null): ResponseInterface
{
return app(HttpKernelInterface::class)->response($code, $exception);
}
}

function redirect(string $uri, int $code = 301):ResponseInterface
{
$response = app(ResponseFactoryInterface::class)->createResponse($code);
return $response->withHeader('Location', $uri);
}
if (!function_exists('_DS\\redirect')) {
function redirect(string $uri, int $code = 301): ResponseInterface
{
$response = app(ResponseFactoryInterface::class)->createResponse($code);
return $response->withHeader('Location', $uri);
}
}

0 comments on commit dd138ca

Please sign in to comment.