My problem is not auto loading in Composer - composer-php

Why does my autoload class not work when I try to include file?
{
"name": "takrayan/microsajjad",
"autoload": {
"psr-4": {
"Takrayan\\Microsajjad\\app\\": "app/"
}
},
"authors": [
{
"name": "sajjad6708",
"email": "102435011+sajjad6708#users.noreply.github.com"
}
],
"require": {
"vlucas/phpdotenv": "^5.4"
}
}

Related

Lumen after upgradation from 5.7 to 6.0 db:seed command not working

I have upgraded from Lumen 5.7 to 6.0. After the upgradation, the artisan db:seeder command is not working. It shows Target class [DatabaseSeeder] does not exist. I have tried running composer dump-autoload but it didn't solve the problem. Below is the composer.json file
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": [
"framework",
"laravel",
"lumen"
],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.1.3",
"guzzlehttp/guzzle": "^7.2",
"laravel/lumen-framework": "^6.0",
"vlucas/phpdotenv": "^3.3"
},
"require-dev": {
"phpunit/phpunit": "~7.0",
"mockery/mockery": "~1.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": []
},
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true,
"allow-plugins": {
"kylekatarnls/update-helper": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Please help
Laravel changed directory of seeders class, (from database/seeds to database/seeders) so you probably need to update your composer.json this way (move seeders in autoload /psr-4):
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/helpers/helpers.php"
]
},
And add namespace to your seeders files :
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
....
Don't forget to run composter dump-autoload after updating your files.

springdoc-openapi: publish enum as reference when enum comes from generated code

I'm using
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.8</version>
</dependency>
For generating client-stubs via openapi-specs and generating my own openapi docoumentation.
I do have an API, lets call it just API-1, which I'm using within my project.
This API does provide an enum, simpfified this one:
#Schema(enumAsRef=true)
public enum SomethingEnum {
A,
B,
C
}
API one does provide an openapi-specification, there the enum is included as schema and referenced. That is all fine.
This enum I'm using in API-2. I let all models from API-1 generate with the openapi-generator-maven-plugin.
API-2 does provide an openapi specification, which looks simplified like this:
{
"paths": {
"/request": {
"get": {
"tags": [
"requests"
],
"operationId": "getSomething",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Something"
}
}
}
}
}
}
}
},
"schemas": {
"Something": {
"type": "object",
"properties": {
"somethingEnum": {
"type": "array",
"items": {
"type": "string",
"enum": [
"A",
"B",
"C"
]
}
},
,
"id": {
"type": "string"
}
}
}
}
}
And here is the problem: The SomethingEnum is not referenced via an Schema.
It should rather look like this:
{
"paths": {
"/request": {
"get": {
"tags": [
"requests"
],
"operationId": "getSomething",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Something"
}
}
}
}
}
}
}
},
"schemas": {
"Something": {
"type": "object",
"properties": {
"SomethingEnum ": {
"$ref": "#/components/schemas/SomethingEnum "
},
"id": {
"type": "string"
}
}
},
"SomethingEnum": {
"type": "string",
"enum": [
"A",
"B",
"C",
]
}
}
}
How can I achieve this? Is there a way I can either
configure the openapi-generator-maven-plugin to annote generated enums automatically with #Schema(enumAsRef=true)
configure springdoc somehow
?
I hope my problem is clear. Thanks for every suggestion.

Class in autoloaded file not recognized

The class definition of \MyOrganization\OurLibrary\Application isn't recognized in a script in a framework package that uses the core library. It is recognized in an exact copy of the script in the core folder. What is the problem, and how do I resolve it?
library/core/Application.php
namespace MyOrganization\OurLibrary;
class Application {
public static function someMethod() ...
}
library/core/composer.json
{
"name": "myorganization/core",
"type": "library",
"config": { "secure-http": false },
"require": { ... }
"require-dev": { ... }
"autoload": {
"files": ["Application.php"],
}
}
library/framework/composer.json
{
"name": "myorganization/framework",
"type": "library",
"require": {
"myorganization/core": "dev-master",
...
},
"require-dev": { ... }
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"repositories": [
{
"type": "path",
"url": "../core",
"options": { "symlink": true }
}
]
}
library/(core|framework)/script.php
require __DIR__.'/vendor/autoload.php';
\MyOrganization\OurLibrary\Application::someMethod();

Laravel 5 load custom package from vendor

I'm trying to load one custom package (lapisraro/autocrud) from vendor file to my project but getting this error:
"Class 'Lapisraro\Autocrud\AutocrudServiceProvider' not found"
Here is my application's composer.json:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"lapisraro/autocrud": "dev-master",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"jeroen-g/laravel-packager": "^2.2",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Lapisraro\\Autocrud\\": "/lapisraro/autocrud/src"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
this is my composer.json inside vendor/lapisraro/autocrud
{
"name": "lapisraro/autocrud",
"description": "Gerador de CRUD padrĂ£o da LapisRaro",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Lucas Campos",
"email": "lucasblind#gmail.com"
}
],
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"Lapisraro\\Autocrud\\": "src/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/",
"Lapisraro\\Autocrud\\": "src/"
}
},
"extra":
{
"laravel":
{
"providers": [ "Lapisraro\\autocrud\\AutocrudServiceProvider" ]
}
}
}
and this is my service provider
<?php
// MyVendor\contactform\src\ContactFormServiceProvider.php
namespace Lapisraro\autocrud;
use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Yajra\DataTables\Facades\DataTables;
//use Intervention\Image\Facades\Image;
//use App\Models\Image as ImgModel;
class AutocrudServiceProvider extends ServiceProvider {
/**
* boot
*
* Initialize provider
*
* #return void
*/
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/routes/web.php');
$this->loadViewsFrom(__DIR__.'/resources/views', 'autocrud');
}
/**
* register
*
* Register the service provider for the dependency.
*
* #return void
*/
public function register()
{
$this->loadRoutesFrom(__DIR__.'/routes/web.php');
$this->loadViewsFrom(__DIR__.'/resources/views', 'autocrud');
//App::register(AutocrudServiceProvider::class);
}
}
?>
I also tried to load that inside config/app.php:
Lapisraro\Autocrud\AutocrudServiceProvider::class,
and this link of my package https://packagist.org/packages/lapisraro/autocrud
Instead of messing with the PSR-4 autoloading in your application's composer.json:
"autoload": {
"psr-4": {
"App\\": "app/",
"Lapisraro\\Autocrud\\": "/lapisraro/autocrud/src"
},
... add your local package to the repositories like this:
"repositories": [
{
"type": "path",
"url": "/lapisraro/autocrud"
}
]
Run composer update or composer dump-autoload afterwards.
I gave up and tried to make this with laravel-packager but dont worked also,
but I found this video https://www.youtube.com/watch?v=H-euNqEKACA and now its working.
the problem was in composer file and folder levels.
Thanks for the help!

Magento2 extensions installation from gitHub

I want to modify one extension from public Github repository (fork) and install it to my Magento2 via composer.
Extensions stored here GitHub. Really, i need only one sample-external-links. I tried many times to configure composer.json in my Magento2 root, but it doesn't work , i receive errors:
[Composer\Downloader\TransportException]
The "https://api.github.com/repos/magento/magento2-samples/sample-external-links" file could not be downloaded (HTTP/1.1 404 Not Found)
How to configure composer to install only 1 package from some repository like that?
my composer.json:
{
"name": "magento/project-community-edition",
"description": "eCommerce Platform for Growth (Community Edition)",
"type": "project",
"version": "2.1.0",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"require": {
"magento/product-community-edition": "2.1.0",
"composer/composer": "#alpha",
"magento/sample-bundle-all": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "4.1.0",
"squizlabs/php_codesniffer": "1.5.3",
"phpmd/phpmd": "#stable",
"pdepend/pdepend": "2.2.2",
"fabpot/php-cs-fixer": "~1.2",
"lusitanian/oauth": "~0.3 <=0.7.0",
"sebastian/phpcpd": "2.0.0"
},
"config": {
"use-include-path": true
},
"autoload": {
"psr-4": {
"Magento\\Framework\\": "lib/internal/Magento/Framework/",
"Magento\\Setup\\": "setup/src/Magento/Setup/",
"Magento\\": "app/code/Magento/"
},
"psr-0": {
"": "app/code/"
},
"files": [
"app/etc/NonComposerComponentRegistration.php"
]
},
"autoload-dev": {
"psr-4": {
"Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
"Magento\\Tools\\": "dev/tools/Magento/Tools/",
"Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/",
"Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
"Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/"
}
},
"minimum-stability": "alpha",
"prefer-stable": true,
"repositories": [
{ "type": "vcs",
"url": "https://github.com/magento/magento2-samples/sample-external-links"
}
],
"extra": {
"magento-force": "override"
}
Could you please try this:
Change
"repositories": [
{ "type": "vcs",
"url": "https://github.com/magento/magento2-samples/sample-external-links"
}
],
to
"repositories": [
{
"type": "vcs",
"url": "git#github.com:samples/sample-external-links.git"
}
],
And then add your module on require:
"require": {
"magento/product-enterprise-edition": "2.2.5",
"composer/composer": "#alpha",
"yourvendor/sample-external-links": "dev-master", // your module should add here
},

Resources