Вызов функции пространства имен для неопределенной функции - PullRequest
0 голосов
/ 28 августа 2018

В настоящее время я вызываю функцию пространства имен из php-файла без пространства имен.

Моя функция определена в:

ReservationValidation.php

namespace App\Reservation;

use Slim\Http\{Request, Response};
use Swaggest\JsonSchema\Schema;

function validateReservationPatch(Request $request, Response $response, callable $next)
{
    try {
        $schema = Schema::import(__DIR__ . '/schemas/patch.json');
        $schema->in(json_decode($request->getBody()));
    } catch(Exception $e) {
        return $response->withStatus(400);
    }

    return $next($request, $response);
}

Я вызываю его из:

route.php

<?php

use App\Auth\Authenticate;
use function App\Reservation\validateReservationPatch;

$reservationPath = '/reservations';

$app->add(new Authenticate())->add(function ($request, $response, $next) {
    validateReservationPatch($request, $response, $next);
})->patch($reservationPath, 'ReservationController:updateReservation');

И я нажал эту ошибку:

Slim Application Error
The application could not run because of the following error:

Details

Type: Error
Message: Call to undefined function 
App\Reservation\validateReservationPatch()
File: E:\workspace\php-playground\residence-reservation-microservice\src\App\Reservation\routes.php
Line: 14
Trace

#0 [internal function]: Closure->{closure}(Object(Slim\Http\Request), 
Object(Slim\Http\Response), Object(Closure))
#1 E:\workspace\php-playground\residence-reservation- 
microservice\vendor\slim\slim\Slim\DeferredCallable.php(43): 
call_user_func_array(Object(Closure), Array)
#2 [internal function]: Slim\DeferredCallable- 
>__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), 
Object(Closure))
#3 E:\workspace\php-playground\residence-reservation- 
microservice\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(70): 
call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), 
Object(Slim\Http\Response), Object(Closure))
#4 E:\workspace\php-playground\residence-reservation- 
microservice\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(117): Slim\App- 
>Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#5 E:\workspace\php-playground\residence-reservation- 
microservice\vendor\slim\slim\Slim\App.php(406): Slim\App- 
>callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 E:\workspace\php-playground\residence-reservation- 
microservice\vendor\slim\slim\Slim\App.php(314): Slim\App- 
>process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 E:\workspace\php-playground\residence-reservation- 
microservice\public\index.php(33): Slim\App->run()
#8 {main}

Я могу вызвать класс пространства имен, но не функцию. Есть идеи?

...