Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Auth/MustAuthenticateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function fails()
*/
public function showLoginPage()
{
View::make('app.auth.login');
return View::make('app.auth.login');
}

/**
Expand All @@ -67,7 +67,7 @@ public function showLoginPage()
*/
public function showMagicLinkPage()
{
View::make('app.auth.password.email');
return View::make('app.auth.password.email');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Auth/MustRegisterNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait MustRegisterNewUser
*/
public function showRegistrationPage()
{
View::make('app.auth.register');
return View::make('app.auth.register');
}

/**
Expand Down
23 changes: 23 additions & 0 deletions Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Modulus\Framework;

use Modulus\Http\Rest;
use Modulus\Utility\View;
use Modulus\Http\Redirect;
use Modulus\Framework\Upstart;

Expand Down Expand Up @@ -40,6 +41,11 @@ public static function make(Upstart $app)
*/
if ($response instanceof Redirect) return $response->send();

/**
* Create a view page
*/
if (Response::isView($response)) return;

/**
* Avoid "Segmentation fault (core dumped)"
*/
Expand All @@ -50,4 +56,21 @@ public static function make(Upstart $app)
*/
return null;
}

/**
* Render a view
*
* @param mixed $response
* @return bool
*/
public static function isView($response) : bool
{
if ($response instanceof View) {
$response->render();

return true;
}

return false;
}
}
136 changes: 136 additions & 0 deletions Upstart/Prototype.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use ReflectionClass;
use ReflectionFunction;
use Modulus\Support\Extendable;
use Modulus\Framework\Exceptions\CannotExtendClassException;
use Modulus\Framework\Exceptions\ClassDoesNotExistException;
Expand Down Expand Up @@ -32,6 +33,63 @@ public function bind(string $class, string $method, Closure $closure)
return $class::bind($method, $closure);
}

/**
* Bind multple methods at the same time
*
* @param string $class
* @param array $methods
* @deprecated
*/
public function bindMany(string $class, array $methods)
{
/**
* Map through the functions
*
* @param Closure $closure
*/
array_map(function ($closure) use ($class) {

$info = new ReflectionFunction($closure);

$doc = explode(PHP_EOL, $info->getDocComment());

/**
* Filter out the stuff that's not needed
*/
array_filter($doc, function($comment) use ($class, $closure) {

/**
* Register a new function if its not commented out
*/
if (str_contains($comment, '@method') && !str_contains($comment, '//')) {

/**
* Filter out "*" and "@method"
*/
$filtered = array_diff(
array_filter(explode(' ', $comment)
), ['*', '@method']);

/**
* Return the name of the method
*/
$method = array_first($filtered, function($value) {
if (ends_with($value, '()')) return $value;
});

/**
* Bind new method to $class
*/
if ($method) {
$this->bind($class, substr($method, 0, strlen($method) - 2), $closure);
}

}

});
}, $methods);
}

/**
* Add custom static function
*
Expand All @@ -53,4 +111,82 @@ public function static(string $class, string $method, Closure $closure)

return $class::static($method, $closure);
}

/**
* Add custom property
*
* @param string $class
* @param string $property
* @param Closure $closure
* @return mixed
*/
public function prop(string $class, string $property, Closure $closure)
{
if (!class_exists($class)) throw new ClassDoesNotExistException("Class {$class} does not exist");

if (!in_array(
Extendable::class,
array_keys((new ReflectionClass($class))->getTraits()))
) {
throw new CannotExtendClassException("Cannot extend \"{$class}::class\"");
}

return $class::prop($property, $closure);
}

/**
* Add multiple props at the same time
*
* @param string $class
* @param array $props
*/
public function hasManyProps(string $class, array $props)
{
/**
* Map through the functions
*
* @param Closure $closure
*/
array_map(function ($closure) use ($class) {

$info = new ReflectionFunction($closure);

$doc = explode(PHP_EOL, $info->getDocComment());

/**
* Filter out the stuff that's not needed
*/
array_filter($doc, function($comment) use ($class, $closure) {

/**
* Register a new prop if its not commented out
*/
if (str_contains($comment, '@var') && !str_contains($comment, '//')) {

/**
* Filter out "*" and "@var"
*/
$filtered = array_diff(
array_filter(explode(' ', $comment)
), ['*', '@var']);

/**
* Return the name of the property
*/
$property = array_last($filtered, function($value) {
if (starts_with($value, '$') && preg_match("/[a-z]|[A-Z]/", $value)) return $value;
});

/**
* Bind new property to $class
*/
if ($property) {
$this->prop($class, substr($property, 1), $closure);
}

}

});
}, $props);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "modulusphp/framework",
"description": "Framework component for Modulus",
"version": "1.9.9.1",
"version": "1.9.9.2",
"license": "MIT",
"type": "package",
"authors": [{
Expand Down