Laravel 5 load custom package from vendor - laravel

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!

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.

My problem is not auto loading in Composer

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"
}
}

Kafka Connect How to make namespace agnostic to database name

My Environment
MySQL(5.7): We have multiple schemas and the naming convention is {application_name}_env.
Example: Consider we have two apps: app1 and app2
Dev Environment: The database names would be app1_dev, app2_dev
QA Environment: The database names would be app1_qa, app2_qa.
Debezium(0.8.3). The plugin is used to CDC MySQL Logs.
Connector Configuration is:
{
"name": "connector-1",
"config": {
"connector.class": "io.debezium.connector.mysql.MySqlConnector",
"tasks.max": "1",
"database.hostname": "mysql",
"database.port": "3306",
"database.user": "debezium",
"database.password": "dbz",
"database.server.id": "184054",
"database.server.name": "dbserver1",
"database.history.kafka.bootstrap.servers": "kafka:9092",
"database.history.kafka.topic": "schema-changes.inventory",
"decimal.handling.mode": "double",
"snapshot.mode": "when_needed",
"table.whitelist":"{database_name}.account",
"key.converter": "io.confluent.connect.avro.AvroConverter",
"value.converter": "io.confluent.connect.avro.AvroConverter",
"key.converter.schema.registry.url": "http://schema-registry:8081",
"value.converter.schema.registry.url": "http://schema-registry:8081",
"transforms" : "setSchema",
"transforms.setSchema.type" : "org.apache.kafka.connect.transforms.SetSchemaMetadata$Value",
"transforms.setSchema.schema.name" : "com.test.Account"
}
}
Spring Java Application I am using Kafka Consumer(#KafkaListener) to read the changes from the Debezium event.
I provide the avsc files and used gradle avro plugin to generate the classes.
Schema from Dev env
{
"type":"record",
"name":"Accounts",
"namespace":"com.test",
"fields":[
{
"name":"before",
"type":[
"null",
{
"type":"record",
"name":"Value",
"namespace":"dbserver1.app1_dev.account",
"fields":[
{
"name":"id",
"type":"long"
}
],
"connect.name":"dbserver1.app1_dev.account.Value"
}
],
"default":null
},
{
"name":"after",
"type":[
"null",
"dbserver1.app1_dev.account.Value"
],
"default":null
},
{
"name":"source",
"type":{
"type":"record",
"name":"Source",
"namespace":"io.debezium.connector.mysql",
"fields":[
{
"name":"version",
"type":[
"null",
"string"
],
"default":null
},
{
"name":"name",
"type":"string"
},
{
"name":"server_id",
"type":"long"
},
{
"name":"ts_sec",
"type":"long"
},
{
"name":"gtid",
"type":[
"null",
"string"
],
"default":null
},
{
"name":"file",
"type":"string"
},
{
"name":"pos",
"type":"long"
},
{
"name":"row",
"type":"int"
},
{
"name":"snapshot",
"type":[
{
"type":"boolean",
"connect.default":false
},
"null"
],
"default":false
},
{
"name":"thread",
"type":[
"null",
"long"
],
"default":null
},
{
"name":"db",
"type":[
"null",
"string"
],
"default":null
},
{
"name":"table",
"type":[
"null",
"string"
],
"default":null
},
{
"name":"query",
"type":[
"null",
"string"
],
"default":null
}
],
"connect.name":"io.debezium.connector.mysql.Source"
}
},
{
"name":"op",
"type":"string"
},
{
"name":"ts_ms",
"type":[
"null",
"long"
],
"default":null
}
],
"connect.name":"com.test.Account"
}
Issue:
Since my database schemas are dynamic i.e they end with env suffix.
The Schema generated in each environment has a different namespace.
Dev: dev.app1_dev.accounts
QA: dev.app1_qa.accounts
Because of the different namespace, I am not able to deserialize my dev code in QA. So If used schema generated in Dev, the code won't work in QA.
I want to make sure that namespace is consistent across all the environments.
Please use org.apache.kafka.connect.transforms.SetSchemaMetadata SMT - see https://github.com/a0x8o/kafka/blob/master/connect/transforms/src/main/java/org/apache/kafka/connect/transforms/SetSchemaMetadata.java

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();

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