Skip to content
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"ext-curl": "*",
"ext-json": "*",
"neuron-php/mvc": "0.8.*",
"neuron-php/mvc": "0.9.*",
"neuron-php/cli": "0.8.*",
"neuron-php/jobs": "0.2.*",
"neuron-php/orm": "0.1.*",
Expand Down
36 changes: 15 additions & 21 deletions src/Cms/Controllers/Admin/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ public function __construct( ?Application $app = null )

/**
* List categories
* @param array $parameters
* @param Request|null $request
* @param Request $request
* @return string
* @throws \Exception
*/
public function index( array $parameters, ?Request $request ): string
public function index( Request $request ): string
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand Down Expand Up @@ -79,12 +78,11 @@ public function index( array $parameters, ?Request $request ): string

/**
* Show create category form
* @param array $parameters
* @param Request|null $request
* @param Request $request
* @return string
* @throws \Exception
*/
public function create( array $parameters, ?Request $request ): string
public function create( Request $request ): string
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand All @@ -109,12 +107,11 @@ public function create( array $parameters, ?Request $request ): string

/**
* Store new category
* @param array $parameters
* @param Request|null $request
* @param Request $request
* @return never
* @throws \Exception
*/
public function store( array $parameters, ?Request $request ): never
public function store( Request $request ): never
{
try
{
Expand All @@ -133,12 +130,11 @@ public function store( array $parameters, ?Request $request ): never

/**
* Show edit category form
* @param array $parameters
* @param Request|null $request
* @param Request $request
* @return string
* @throws \Exception
*/
public function edit( array $parameters, ?Request $request ): string
public function edit( Request $request ): string
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand All @@ -147,7 +143,7 @@ public function edit( array $parameters, ?Request $request ): string
throw new \RuntimeException( 'Authenticated user not found' );
}

$categoryId = (int)$parameters['id'];
$categoryId = (int)$request->getRouteParameter( 'id' );
$category = $this->_categoryRepository->findById( $categoryId );

if( !$category )
Expand All @@ -172,14 +168,13 @@ public function edit( array $parameters, ?Request $request ): string

/**
* Update category
* @param array $parameters
* @param Request|null $request
* @param Request $request
* @return never
* @throws \Exception
*/
public function update( array $parameters, ?Request $request ): never
public function update( Request $request ): never
{
$categoryId = (int)$parameters['id'];
$categoryId = (int)$request->getRouteParameter( 'id' );
$category = $this->_categoryRepository->findById( $categoryId );

if( !$category )
Expand All @@ -204,14 +199,13 @@ public function update( array $parameters, ?Request $request ): never

/**
* Delete category
* @param array $parameters
* @param Request|null $request
* @param Request $request
* @return never
* @throws \Exception
*/
public function destroy( array $parameters, ?Request $request ): never
public function destroy( Request $request ): never
{
$categoryId = (int)$parameters['id'];
$categoryId = (int)$request->getRouteParameter( 'id' );

try
{
Expand Down
7 changes: 5 additions & 2 deletions src/Cms/Controllers/Admin/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Neuron\Cms\Controllers\Content;
use Neuron\Cms\Auth\CsrfTokenManager;
use Neuron\Cms\Auth\SessionManager;
use Neuron\Core\Exceptions\NotFound;
use Neuron\Mvc\Application;
use Neuron\Mvc\Requests\Request;
use Neuron\Mvc\Responses\HttpResponseStatus;
use Neuron\Patterns\Registry;

Expand All @@ -29,10 +31,11 @@ public function __construct( ?Application $app = null )

/**
* Show admin dashboard
* @param array $parameters
* @param Request $request
* @return string
* @throws NotFound
*/
public function index( array $parameters ): string
public function index( Request $request ): string
{
// Get authenticated user from Registry
$user = Registry::getInstance()->get( 'Auth.User' );
Expand Down
48 changes: 24 additions & 24 deletions src/Cms/Controllers/Admin/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Neuron\Cms\Auth\SessionManager;
use Neuron\Data\Setting\SettingManager;
use Neuron\Mvc\Application;
use Neuron\Mvc\Requests\Request;
use Neuron\Mvc\Responses\HttpResponseStatus;
use Neuron\Patterns\Registry;

Expand All @@ -25,7 +26,6 @@
*/
class Posts extends Content
{

private DatabasePostRepository $_postRepository;
private DatabaseCategoryRepository $_categoryRepository;
private DatabaseTagRepository $_tagRepository;
Expand Down Expand Up @@ -72,11 +72,11 @@ public function __construct( ?Application $app = null )

/**
* List all posts
* @param array $parameters
* @param Request $request
* @return string
* @throws \Exception
*/
public function index( array $parameters ): string
public function index( Request $request ): string
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand Down Expand Up @@ -119,11 +119,11 @@ public function index( array $parameters ): string

/**
* Show create post form
* @param array $parameters
* @param Request $request
* @return string
* @throws \Exception
*/
public function create( array $parameters ): string
public function create( Request $request ): string
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand Down Expand Up @@ -153,11 +153,11 @@ public function create( array $parameters ): string

/**
* Store new post
* @param array $parameters
* @param Request $request
* @return never
* @throws \Exception
*/
public function store( array $parameters ): never
public function store( Request $request ): never
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand Down Expand Up @@ -201,11 +201,11 @@ public function store( array $parameters ): never

/**
* Show edit post form
* @param array $parameters
* @param Request $request
* @return string
* @throws \Exception
*/
public function edit( array $parameters ): string
public function edit( Request $request ): string
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand All @@ -214,7 +214,7 @@ public function edit( array $parameters ): string
throw new \RuntimeException( 'Authenticated user not found' );
}

$postId = (int)$parameters['id'];
$postId = (int)$request->getRouteParameter( 'id' );
$post = $this->_postRepository->findById( $postId );

if( !$post )
Expand Down Expand Up @@ -250,11 +250,11 @@ public function edit( array $parameters ): string

/**
* Update post
* @param array $parameters
* @param Request $request
* @return never
* @throws \Exception
*/
public function update( array $parameters ): never
public function update( Request $request ): never
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand All @@ -263,7 +263,7 @@ public function update( array $parameters ): never
throw new \RuntimeException( 'Authenticated user not found' );
}

$postId = (int)$parameters['id'];
$postId = (int)$request->getRouteParameter( 'id' );
$post = $this->_postRepository->findById( $postId );

if( !$post )
Expand All @@ -280,14 +280,14 @@ public function update( array $parameters ): never
try
{
// Get form data
$title = $_POST['title'] ?? '';
$slug = $_POST['slug'] ?? '';
$content = $_POST['content'] ?? '';
$excerpt = $_POST['excerpt'] ?? '';
$featuredImage = $_POST['featured_image'] ?? '';
$status = $_POST['status'] ?? Post::STATUS_DRAFT;
$categoryIds = $_POST['categories'] ?? [];
$tagNames = $_POST['tags'] ?? '';
$title = $request->post( 'title', '' );
$slug = $request->post('slug', '' );
$content = $request->post( 'content', '' );
$excerpt = $request->post( 'excerpt' ,'' );
$featuredImage = $request->post( 'featured_image', '' );
$status = $request->post( 'status', Post::STATUS_DRAFT );
$categoryIds = $request->post( 'categories', [] );
$tagNames = $request->post( 'tags','' );

// Update post using service
$this->_postUpdater->update(
Expand All @@ -312,10 +312,10 @@ public function update( array $parameters ): never

/**
* Delete post
* @param array $parameters
* @param Request $request
* @return never
*/
public function destroy( array $parameters ): never
public function destroy( Request $request ): never
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand All @@ -324,7 +324,7 @@ public function destroy( array $parameters ): never
throw new \RuntimeException( 'Authenticated user not found' );
}

$postId = (int)$parameters['id'];
$postId = (int)$request->getRouteParameter( 'id' );
$post = $this->_postRepository->findById( $postId );

if( !$post )
Expand Down
19 changes: 10 additions & 9 deletions src/Cms/Controllers/Admin/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Neuron\Cms\Auth\CsrfTokenManager;
use Neuron\Data\Setting\SettingManager;
use Neuron\Mvc\Application;
use Neuron\Mvc\Requests\Request;
use Neuron\Mvc\Responses\HttpResponseStatus;
use Neuron\Patterns\Registry;

Expand Down Expand Up @@ -42,11 +43,11 @@ public function __construct( ?Application $app = null )

/**
* Show profile edit form
* @param array $parameters
* @param Request $request
* @return string
* @throws \Exception
*/
public function edit( array $parameters ): string
public function edit( Request $request ): string
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand Down Expand Up @@ -81,11 +82,11 @@ public function edit( array $parameters ): string

/**
* Update profile
* @param array $parameters
* @param Request $request
* @return never
* @throws \Exception
*/
public function update( array $parameters ): never
public function update( Request $request ): never
{
$user = Registry::getInstance()->get( 'Auth.User' );

Expand All @@ -94,11 +95,11 @@ public function update( array $parameters ): never
throw new \RuntimeException( 'Authenticated user not found' );
}

$email = $_POST['email'] ?? '';
$timezone = $_POST['timezone'] ?? '';
$currentPassword = $_POST['current_password'] ?? '';
$newPassword = $_POST['new_password'] ?? '';
$confirmPassword = $_POST['confirm_password'] ?? '';
$email = $request->post( 'email', '' );
$timezone = $request->post( 'timezone', '' );
$currentPassword = $request->post( 'current_password', '' );
$newPassword = $request->post( 'new_password', '' );
$confirmPassword = $request->post( 'confirm_password', '' );

// Validate password change if requested
if( !empty( $newPassword ) )
Expand Down
Loading