Restler is refusing to instantiate any of my API classes. It's just always saying it fails on Route, but doesn't bother to provide any other useful information. I installed Restler via composer via "restler/framework" : "3.0.0-RC6" and then created an index.php that looks like this:
<?php
require __DIR__.'/../vendor/autoload.php';
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('Explorer');
$r->addAPIClass('Play');
$r->handle();
In the exact same directory as the index.php I've created a file called Play.php that looks like so:
<?php
public class Play
{
public function __construct() {
error_log("I called the constructor!\n", 3, '/tmp/scott');
}
public function index() {
error_log("I called the index\n", 3, '/tmp/scott');
}
When I call http://.../api/play I never see the /tmp/scott file created, and I just get the generic failure response from Restler:
{
"error": {
"code": 404,
"message": "Not Found"
},
"debug": {
"source": "Routes.php:438 at route stage",
"stages": {
"success": [
"get"
],
"failure": [
"route",
"negotiate",
"message"
]
}
}
}
As Luracast noted in the comments, I had to edit the composer.json to add this stanza:
"autoload": {
"psr-0": {
"": "api"
}
}
and then run composer dump-autoload
Related
I am new to PHP and found the router component of the coffeecode/router. I'm following the creator's own tutorial.
my index.php:
<?php
require __DIR__ . "/vendor/autoload.php";
use CoffeeCode\Router\Router;
$router = new Router(URL);
$router->namespace("Source\Controle");
$router->group(null);
$router->get("/", "Web:home");
$router->get("/{filter}", "Web:home");
$router->get("/contato", "Web:contato");
$router->dispatch();
?>
my index.php:my Web.php (controlling class):
<?php
namespace Source\Controle;
class Web
{
public function home($data)
{
echo "<h1>Home</h1>";
}
public function contato($data)
{
echo "<h1>Contato</h1>";
}
}
?>
my composer.json:
{
"name": "jao/rotas",
"require": {
"coffeecode/router": "2.0.*"
},
"autoload": {
"psr-4": {
"Source\\": "src/"
},
"files":["src/Config.php"]
},
"authors": [
{
"name": "João Victor",
"email":
}
]
}
and my Config.php (file that arrows the global link):
<?php define("URL", "http://localhost/rotas") ?>
So is my folder hierarchy:
hierarchy
When I access /home the home() method of classand Web is called normally, but when i access /contact the page returns error 404.
page
What may be causing this error? why doesn't the /contact return me to the contact page?
I know the title topic sounds similar to other questions, but I've searched many topics on stackoverflow and none resolve my issue.
I am currently developing a package under Laravel ^8.12, below the content of the function that register my routes:
protected function registerRoutes(): void
{
Route::prefix('workflowmakr')
->namespace('AlvariumDigital\WorkflowMakr\Http\Controllers')
->as('workflowmakr.')
->middleware(config('workflowmakr.routes_middleware'))
->group(__DIR__ . '/../routes/api.php');
}
And below is the content of the routes/api.php file:
<?php
use Illuminate\Support\Facades\Route;
Route::resource('actions', 'ActionController')->except(['created', 'edit']);
Route::resource('scenarios', 'ScenarioController')->except(['created', 'edit']);
Route::resource('statuses', 'StatusController')->except(['created', 'edit']);
Route::resource('transitions', 'TransitionController')->except(['created', 'edit']);
For a better view of the project architecture, below is a screenshot of the packages folder containing the package under development:
And finally, below is the composer.json declaring my package:
...
"extra": {
"laravel": {
"providers": [
"AlvariumDigital\\WorkflowMakr\\WorkflowMakrServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/",
"AlvariumDigital\\WorkflowMakr\\": "packages/AlvariumDigital/WorkflowMakr/src/"
}
},
...
When I execute the command php artisan route:list to view all my routes I got this error :
$> php artisan route:list
Illuminate\Contracts\Container\BindingResolutionException
Target class [AlvariumDigital\WorkflowMakr\Http\Controllers\ActionController] does not exist.
at D:\Films\R_D\Laravel packages\workflow-makr\vendor\laravel\framework\src\Illuminate\Container\Container.php:832
828▕
829▕ try {
830▕ $reflector = new ReflectionClass($concrete);
831▕ } catch (ReflectionException $e) {
➜ 832▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
833▕ }
834▕
835▕ // If the type is not instantiable, the developer is attempting to resolve
836▕ // an abstract type such as an Interface or Abstract Class and there is
1 [internal]:0
Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
2 D:\Films\R_D\Laravel packages\workflow-makr\vendor\laravel\framework\src\Illuminate\Container\Container.php:830
ReflectionException::("Class AlvariumDigital\WorkflowMakr\Http\Controllers\ActionController does not exist")
EDIT
Below is the content of the ActionController file:
<?php
namespace AlvariumDigital\WorkflowMakr\Http\Controllers;
use AlvariumDigital\Models\Action;
use AlvariumDigital\WorkflowMakr\Helpers\Constants;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class ActionController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\JsonResponse
*/
public function index()
{
$query = Action::query();
if (config('workflowmakr.pagination_size') == -1) {
return response()->json($query->get(), 200);
}
return response()->json($query->paginate(config('workflowmakr.pagination_size')), 200);
}
// ...
}
EDIT 2
The content of the package composer.json file:
{
"name": "AlvariumDigital/WorkflowMakr",
"description": "Generalize the management of your workflows",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Alvarium Digital",
"email": "contact#alvariumdigital.com",
"homepage": "http://www.alvariumdigital.com",
"role": "Corporate"
},
{
"name": "EL OUFIR Hatim",
"email": "heloufir#alvariumdigital.com",
"homepage": "https://www.linkedin.com/in/eloufirhatim/",
"role": "Developer"
}
],
"support": {
"email": "heloufir#alvariumdigital.com"
},
"minimum-stability": "dev",
"require": {}
}
Did I do something wrong or incomplete?
You can ask for more details if needed.
Thanks
You have structured this directory incorrectly. You have the PSR4 autoloading loading the src directory as the namespace. Your controllers are not in the src folder, only the Service Provider is in there. So to composer there are no files for it to find and autoload based on your PSR4 autoloading.
I have created a custom Laravel package. Its hosted on a private repository.
When I try to install the package in a Laravel application like this:
composer require memberportal/congress-models
I get this error:
In ProviderRepository.php line 208:
Class 'Memberportal\CongressesModels\CMServiceProvider' not found
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Installation failed, reverting ./composer.json to its original content.
I have double checked everything a hundred times, but I am clueless why he doesn't find the class CMServiceProvider.php.
Do I need to specify the provider anywhere else then in the composer.json?
This is the content of composer.json from my package:
{
"name": "memberportal/congress-models",
"description": "Takes care of the models between API and client",
"type": "metapackage",
"authors": [
{
"name": "My name",
"email": "my#email.com"
}
],
"version" : "1.0",
"minimum-stability": "stable",
"require": {
"laracasts/presenter": "^0.2.2"
},
"require-dev": {
"orchestra/testbench": "^4.0"
},
"autoload": {
"psr-4": {
"Memberportal\\CongressesModels\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Memberportal\\CongressesModels\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
"Memberportal\\CongressesModels\\CMServiceProvider"
]
}
}
}
This is the folder structure:
This is the content of CMServiceProvider.php:
<?php
namespace Memberportal\CongressesModels;
use Illuminate\Support\ServiceProvider;
class CMServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* #return void
*/
public function register()
{
}
/**
* Bootstrap services.
*
* #return void
*/
public function boot()
{
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
}
}
Since you want to install a Laravel package your package type should be package. A metapackage is a package that does not contain actual software, it simply depends on other packages to be installed.
In short, change
"type": "metapackage",
to
"type": "package",
and Laravel will find the service provider with auto-discovery when the package is required by composer.
When I try to reach the backend of the extension I made for TYPO3 v9.5.9, I get this error message:
To fix it, I want to find out which class/ method is throwing this error message. Does anyone know how I can find that out?
my composer.json file looks like this:
{
"name": "secsign/secsign",
"type": "typo3-cms-extension",
"description": "This extension allows users to authenticate using their smart phone running the SecSign App.",
"authors": [
{
"name": "SecSign Technologies Inc.",
"role": "Developer"
}
],
"require": {
"typo3/cms-core": "^9.5"
},
"autoload": {
"psr-4": {
"Secsign\\Secsign\\": "Classes"
}
},
"autoload-dev": {
"psr-4": {
"Secsign\\Secsign\\Tests\\": "Tests"
}
},
"replace": {
"secsign/secsign": "self.version",
"typo3-ter/secsign": "self.version"
}
}
make sure you added something like this in your composer.json (when the file is from a custom ext, not 3rd party)
{
// ...
"autoload": {
"psr-4": {
"Secsign\\Secsign\\": "web/typo3conf/ext/SECSIGNEXT/Classes/",
}
}
// ...
}
Make sure your autoload configuration in composer.json of your extension is correct. https://getcomposer.org/doc/04-schema.md#psr-4
Run "composer dumpautoload" / Or use the button in the Install Tool if this is a non-composer installation
Flush all caches
I'm trying to figure out how to reference a custom class using composer
my composer.json file looks like this:
{
"name": "adtools_api",
"repositories": [
{
"type": "package",
"package": {
"name": "qz/adtools_middleware",
"version": "dev-master",
"source": {
"url": "repo-name",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"slim/slim": "2.*",
"qz/adtools_middleware": "src/"
}
}
and the folder structure looks like this:
app
routes
vendor
composer
qz
adtools_middleware
src
hello-world.php
slim
composer.json
index.php
I'm trying to reference the hello-world.php file which looks like this:
<?php
namespace HelloWorld;
class SayHello
{
public static function world()
{
return 'Hello World, Composer!';
}
}
?>
In the index.php file I'm trying to reference the class like this:
$hello = new HelloWorld\SayHello();
but getting an error telling me "Fatal error: Class 'HelloWorld\SayHello' not found in..."
If anyone can point me in the right direction that would be great! Thank you!
Can you check the autoload inside the vendor folder and see if your HelloWorld namespace is loaded?
If not, you may need to add autoload attribute to your composer.json file, like this
{
"autoload": {
"psr-0": {"HelloWorld": "qz/adtools_middleware/src/"}
},
to load the HelloWorld namespace in your project