Giter Club home page Giter Club logo

core's Introduction

tests status code coverage latest stable version
total downloads license chat

Apiato Logo

Build scalable API's faster | With PHP 8.0 and Laravel 10.0

About Apiato

Apiato is a framework for building scalable and testable API-Centric Applications with PHP, build on top of Laravel.

It is designed to help you build scalable API's faster, by providing tools and functionalities that facilitate the development of any API-Centric App.

Apiato is built using Porto, a new architectural pattern and comes with an amazing list of features:

Learning Apiato

Apiato has an extensive and thorough documentation.

Support and Community

For free community support, join our Discord server.

Contributing

Thank you for considering contributing to the Apiato framework! The contribution guide can be found in the Apiato documentation.

Code of Conduct

In order to ensure that the Apiato community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

If you discover a security vulnerability within Apiato, please send an e-mail to Mohammad Alavi via [email protected]. All security vulnerabilities will be promptly addressed.

Project Maintainers


Mahmoud Zalt
@mahmoudz

Mohammad Alavi
@Mohammad-Alavi

Moslem Deris
@mderis

core's People

Contributors

ab192130 avatar abdolrhman avatar adcuz avatar agnonym avatar anthonyvancauwenberghe avatar denis019 avatar dependabot[bot] avatar domasweb avatar drummer01 avatar emanuellarini avatar fosron avatar fwidm avatar jackardios avatar johannesschobel avatar kyslik avatar lloricode avatar mahmoudz avatar matejschwartz avatar mderis avatar mohammad-alavi avatar petermein avatar phuocnt0612 avatar polarikus avatar rdehnhardt avatar shalawani avatar yalsicor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

core's Issues

Ship Blade Resource Views (has not found and not loaded)

Description:
When iam call a view in ship (/app/ship/Views), shown View [parent] not found.. But if i place in (app/Ship/Mails/Templates/) has found.

Expected Behavior:
When in place resource views in folder /app/ship/Views must be found too.

Additional Context:
I had already fix this bugs with add the vendor apiato,
laravel-api/vendor/apiato/core/Loaders/ViewsLoaderTrait.php
add the new basePath loder with
base_path('app/Ship/Views/'); inside function loadViewsFromShip and load them

Versions:
Apiato Version: 10.x
PHP Version: 8

Steps To Reproduce:

  1. Create Folder Views in app/Ship
  2. Create some resource blade files inside folder Views (app/Ship/Views)
  3. Load that view in some appSection Controller with view('ship::some-file')
  4. It will be not found resrouce file, but expected found

Broken controller generator

Apiato Core Version

8.7.x

PHP Version

8.2

Database Driver & Version

Postgres

Description

The controller generator is setting all new controllers to the containeraName as the resource for the controller.

Steps To Reproduce

Say you have a container named Locations and you have a model named District (which is not the default model created on creating the container)

You run the create controller command.
Screenshot 2024-01-19 at 20 12 46

The generated controller is pointing to the Locations model (container name) yet it is supposed to point to the desired model. Its is doing so for the request, resourceName and transformer.
This is the out come:
Screenshot 2024-01-19 at 20 15 57

Content-Type Response Header

Description:

I keep my images on aws s3, when user try to get image, he use api route
Route::get('files/{id}', [FindFileByIdController::class, 'findFileById'])
so next step I check access to file, if all good give a image,
Task => return Image::make(Storage::disk('s3')->get($file->path));
Controller =>

$file = app(FindFileByIdAction::class)->run($request);

        return response(
            $file->response(), 200,
            [
                'Content-Type' => $file->type,
                'Content-Disposition' => "attachment; filename=" . $file->name .""
            ]);

But Content Type not changed, stay json and image broke, but i set a truth content type, can i resolve this problem?

Maybe this is not quite a bug, but I would really appreciate your help)

Fotos

image

Versions:

  • Apiato Version: 11
  • PHP Version: 8

Add support to middleware prioritization

Expected Behavior

Laravel's middleware prioritization should work with Apiato after adding middlewares to $middlewarePriority.

Actual Behavior

After adding middlewares to $middlewarePriority in any MiddlewareServiceProvider those middlewares are not registered in the router.

Steps to Reproduce the Problem

  1. Try to execute a middleware (that is not defined in the route definition) before the Authencate middleware.

Specifications

  • Apiato Version: 2.4

Additional Details

I found this issue because I needed a container's middleware to be executed after the Authenticate middleware. Due to the Authenticate middleware is registered in the router instance after all the containers' middlewares are registered, the containers' middlewares are always executed before the Authenticate middleware. in fact, the containers' middlewares are executed before the throttle.

Apiato caller style (containerName@className) warning message

The error message It is recommended to use the apiato caller style (containerName@className) for gets really annoying and fills up the log, and we do not mind having containers "linked" (as this is the main reason i can see by reading docs http://docs.apiato.io/miscellaneous/magical-call/ for this call style). It would be good to have an option to turn off this and other future "nice to have" warning errors.

Maybe there's another way around this, but having some other error messages with warning, that do matter, changing log level app-wide is not an option. Maybe we should change this to debug/info level?

Event handling support

PR #38 does the event handling properly (on dispatching) + removes the need for specifying the repository name (get's it from the container where the repository is located in). Please consider merging it

Laravel 6 instalation problem

There is a problem with a "optimus/heimdal" when I try to install the core in my project with Laravel 6.

Problem 1
    - Installation request for laravel/framework (locked at v6.0.0, required as ^6.0) -> satisfiable by laravel/framework[v6.0.0].
    - apiato/core 2.4.7 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core 2.4.x-dev requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core v2.4.0 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core v2.4.1 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core v2.4.2 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core v2.4.3 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core v2.4.4 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core v2.4.5 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core v2.4.6 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - apiato/core v2.4.8 requires optimus/heimdal ~1.5 -> satisfiable by optimus/heimdal[1.5.0].
    - Conclusion: don't install optimus/heimdal 1.5.0
    - Installation request for apiato/core ^2.4 -> satisfiable by apiato/core[2.4.7, 2.4.x-dev, v2.4.0, v2.4.1, v2.4.2, v2.4.3, v2.4.4, v2.4.5, v2.4.6, v2.4.8].

CamelCase not Supported in Model

Description:

When The Model name is camel case, like NewItem, the database table is created as newitems, but when you try to call any query from a related Model, the table named as new_items.

if you try to use the relation function without specifying the table, you get error result. as the laravel will try to find the camelCase model class as new_items.

Easy to fix by declaring protected $table="newitems" in the model, and will work.

this should not be the case.

Expected Behavior:

the migration generator should create table as new_items. to fix the problem.
so that we don't have to name the table in the model.

Versions:

  • Apiato Version: 10.0.3
  • PHP Version: 8.#.#

Search Query Parameter with hashId

Expected to use hashid in search param but had to use real id

tested as admin on: {{url}}/v1/users?search=id:1 with HASH_ID=true in .env

\Apiato\Core\Abstracts\Events\Dispatcher\Dispatcher is not available on DatabaseServiceProvider boot

Apiato EventServiceProvider (\Apiato\Core\Abstracts\Events\Dispatcher\Dispatcher) has been registered on ApiatoProvider boot method
https://github.com/apiato/core/blob/master/Providers/ApiatoProvider.php#L80
which cause the bug that Apiato Dispatcher is not available on DatabaseServiceProvider boot method https://github.com/illuminate/database/blob/master/DatabaseServiceProvider.php#L25
so instead the Apiato Dispatcher we are getting Illuminate\Events\Dispatcher

The solution will be to register Apiato EventServiceProvider before booting.
This issue is related with apiato/apiato#428

PHP 8.1 warning on passing `null` to `explode`

When running on PHP 8.1, hits to API endpoints will emit a warning that says:

explode(): Passing null to parameter #2 ($string) of type string is deprecated in /var/www/html/vendor/apiato/core/Traits /ResponseTrait.php on line 90

originating from this line in parseRequestedIncludes function in ResponseTrait:

protected function parseRequestedIncludes(): array
{
return explode(',', Request::get('include'));
}

Due to Request::get('include') returning null and accepting null has been deprecated.

The same thing may happen to the function before it, since there's also a call to Request::get('filter') and then the return value gets exploded in the following line.

Seems easy to fix, such as by adding ?? '' to them, also maybe there are more places where Apiato calls explode on a possibly null/falsy value?

FactoriesLoaderTrait fail to load factories while testing using ssh on laradock

My Apiato App is running on Laradock. For testing, I use PhpStorm and ssh to laradock. Problem occurs because in my case $newFactoriesPath already has base_path() included and later it gets prepended again.
Had to change

$newFactoriesPath = $loadersDirectory . '/FactoryMixer';

into
$newFactoriesPath = str_replace_first(base_path(), '', $loadersDirectory) . '/FactoryMixer';

CacheableRepository return type error

// Declaration of 

Prettus\Repository\Traits\CacheableRepository::paginate($limit = null, $columns = [...], $method = 'paginate') 

// must be compatible with 

Apiato\Core\Abstracts\Repositories\Repository::paginate($limit = null, $columns = [...], $method = 'paginate'): mixed

Call to a member function hasPermissionTo() on null

Apiato Core Version

8.7.0

PHP Version

8.2

Database Driver & Version

No response

Description

protected function hasAnyPermissionAccess($user): array
{
if (!array_key_exists('permissions', $this->access) || !$this->access['permissions']) {
return [];
}
$permissions = is_array($this->access['permissions']) ? $this->access['permissions'] :
explode('|', $this->access['permissions']);
return array_map(static function ($permission) use ($user) {
return $user->hasPermissionTo($permission);
}, $permissions);
}

This method triggers a "Call to a member function hasPermissionTo() on null" error if the middleware is removed from the Route, for example.

1

And if there is any value in the Permissions block in the Request.

2

I think the solution would be to check for the existence of $user in the closure before passing it to the anonymous function.

return array_map(static function ($permission) use ($user) {
return $user->hasPermissionTo($permission);
}, $permissions);

Steps To Reproduce

  1. Set values for checking in the Permissions block in the Request.
    2
  2. Remove the middleware method from the Route if it exists.
    1
  3. Pass this Request to a WebController.
    3
  4. Make a request to this Route.

why we override tearDown method

As you can see, apiato override tearDown method

public function tearDown()

I think, we don't need to refresh database, cause Illuminate\Foundation\Testing\TestCase done with it, you can see at tearDown method at Illuminate\Foundation\Testing\TestCase

PS: I have tried to test it (with remove tearDown method in Apiato\Core\Abstracts\Tests\PhpUnit\TestCase), and it work (using file or :memory db)

Code Quality for Core Package

So after this problem i've found #40 , i think this repo should have a code quality tool hooked up. As the apiato Ship container has a dependency of master repo, these kinds of errors should not slip through.

API stop working when cache rebuild

Description:

I did a fresh installation as mentioned in the documentation. I am able to navigate to apiato.test and api.apito.test. Till here everything is okay. As soon as I execute the command php artisan config:cache api.apiato.test show the page of apiato.test and all the api's stop working

Expected Behavior:

php artisan config:cache should not impact the api working as this is common to execute this commad

Versions:

  • Apiato Version: 10.0.0
  • PHP Version: 8.0.7

Steps To Reproduce:

  1. composer create-project apiato/apiato my-api
  2. cd my-api
  3. composer update
  4. php artisan migrate
  5. php artisan db:seed
  6. php artisan apiato:permissions:toRole admin
  7. php artisan passport:install
  8. php artisan config:cache

Please let me know in case if I am missing something

Composer update is exexuted due to this error

Running composer update to apply merge settings
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/framework is locked to version v8.43.0 and an update of this package was not requested.
    - league/flysystem 1.1.3 conflicts with roave/security-advisories dev-latest.
    - laravel/framework v8.43.0 requires league/flysystem ^1.1 -> satisfiable by league/flysystem[1.1.3].
    - Root composer.json requires roave/security-advisories dev-latest -> satisfiable by roave/security-advisories[dev-latest].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Update to apply merge settings failed, reverting ./composer.lock to its original content.
> @php artisan key:generate --ansi

Apiato::call fails to set UI

When calling an Action or Task by using Apiato::call('Container@ActionOrTask') this fails to set the UI correctly (is set to null).

This is because of the CallableTrait::setUIIfExists()..

This method tries to read property_exists($this, 'ui'). However, in the context of calling it via Apiato::call(), the $this is Apiato and not the corresponding container.. Therefore, this fails..

Not a major bug, but anyway ;)

Exception when try to generate an WEB CRUD Controller from generator

When try to generate a web crud crontroller from cli command php artisan apiato:generate:controller and exception is returned after setting the follow options:

laradock@7ea54c192cf0:/var/www/apiato$ php artisan apiato:generate:controller

 Enter the name of the Section [AppSection]:
 > 

 Enter the name of the Container:
 > Authorization

 Enter the name of the Controller file [Controller]:
 > RolesController

> Generating (RolesController) in (AppSection:Authorization) Container.

 Select the UI for the controller [API]:
  [0] API
  [1] WEB
 > 1

 Select the Stub you want to load [Generic]:
  [0] Generic
  [1] CRUD.API
  [2] CRUD.WEB
 > 2

File does not exist at path /var/www/apiato/vendor/apiato/core/Generator/Stubs/controllers/web/crud.web.stub.

  Illuminate\Contracts\Filesystem\FileNotFoundException 

  File does not exist at path /var/www/geus-2/vendor/apiato/core/Generator/Stubs/controllers/web/crud.web.stub.

  at vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:59
     55▕         if ($this->isFile($path)) {
     56▕             return $lock ? $this->sharedGet($path) : file_get_contents($path);
     57▕         }
     58▕ 
  ➜  59▕         throw new FileNotFoundException("File does not exist at path {$path}.");
     60▕     }
     61▕ 
     62▕     /**
     63▕      * Get contents of a file with shared access.

      +15 vendor frames 
  16  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

Checking the refered path the stub file crud.web.stub.not exist, maybe changed to crud.stub?

Adding "FindContainerDependenciesCommand" to the core

Hi, I've shown you the FindContainerDependenciesCommand on slack already and you gave me the following feedback:

The only problem is, if the user is injecting the command as dependency and not using the call function. I'd suggest simply adding a warning message when the command is executed to let users know about this.

I've since modified the command to now support both ways to call other scripts - Apiato::call('x@y') and direct uses use App\Contianers\x with two different regex versions. It also parses the container's composer.json to provide more information (you might have two containers with the same name by different authors on different APIs).

My questions:

  1. Was this your mentioned concern with the Apiato::callmethods?
  2. Where would you place the Command & Transformer?

Current version:
Available in the following gist: https://gist.github.com/FWidm/f09aaa852a03e857eabf33990b2fb0af

Sample Output:

$ php artisan apiato:container-dependencies app/Containers/User/
Searching for dependencies in container: app/Containers/User/

 Remove own container from listings? (y/n):
 > y

Found dependencies:
[imports]: 
    [Authorization]: 
        [0]: app/Containers/User/Actions/CreateAdminAction.php
        [1]: app/Containers/User/Data/Seeders/UserPermissionsSeeder_1.php
        [2]: app/Containers/User/UI/API/Transformers/UserTransformer.php

    [Authentication]: 
        [0]: app/Containers/User/Actions/DeleteUserAction.php
        [1]: app/Containers/User/Actions/GetMyProfileAction.php

    [Stripe]: 
        [0]: app/Containers/User/Models/User.php




 Display Container author and description from the composer.json?(y/n):
 > y

[name]: apiato/authorization
[description]: apiato/authorization

[name]: apiato/authentication
[description]: apiato/authentication

[name]: apiato/stripe
[description]: apiato/stripe

Functional problem with API_PREFIX

Description:

I install a fresh apiato 12.
In .env:

Expected Behavior:

Tests work fine

Additional Context:

Versions:

  • Apiato Version: 12.0.0
  • PHP Version: 8.2

Steps To solve:

  1. File vendor/apiato/core/Traits/TestTraits/PhpUnit/TestRequestHelperTrait.php function buildUrlForUri
  2. Add apiato.api.prefix to uri:
private function buildUrlForUri($uri): string
    {
        /// Add this line to use api_prefix from .env file
        $uri = Config::get('apiato.api.prefix') . $uri;
        // add `/` at the beginning in case it doesn't exist
        if (!Str::startsWith($uri, '/')) {
            $uri = '/' . $uri;
        }
        return Config::get('apiato.api.url') . $uri;
    }

Fix Problem with Migration in Generator

If you run the php artisan apiato:generate:container:api command several times, multiple migration files are generated. I already have an idea how to fix it - need time to implement it..

This is just a friendly reminder for myself in order to fix it ;)

@Mahmoudz can you please assign me to this task?

[Discussion] Useful Commands?

Inspired by #45, this is some sort of "What do you think" list of possible useful commands?

As there is already a apiato:actions command, that list all available actions, why not do something like this:

  • rename the signature to apiato:list:actions
  • create a apiato:list:tasks command that list all tasks
  • create a apiato:list:dependencies command from #45

Any additional ideas?

method ::factory() in model apiato 11.0.0

Description:

When running tests (php artisan test) on apiato 11, most tests fail.
Most tests fail because of incorrect namespace fabric classes:
Class "App\Containers\AppSection\User\Data\Factories\Containers\AppSection\User\Models\UserFactory" not found
image

Expected Behavior:

When calling a static method ::fabric in model - The correct namespace is formed "App\Containers\AppSection\User\Data\Factories\UserFactory"

Additional Context:

I found the problem in a trait FactoryLocatorTrait:
function !class_exists($nameSpace . $className . 'Factory', false) return true, Although it should return false

Versions:

  • Apiato Version: 11.0.0
  • PHP Version: 8.0.18

Steps To Reproduce:

  1. Call method User::factory();
  2. Cath exception Class "App\Containers\AppSection\User\Data\Factories\Containers\AppSection\User\Models\UserFactory" not found

Authentication testing environment

Hi, it is possible to set authentication ($this->getTestingUser()) with seeded user?
like this

      
      $user = User::find($id);
      $this->getTestingUser($user);

to test the specific role of possible access,

because the $this->getTestingUser(); is create fresh without any ralation on seeded data on other model

Error on container creation: Container already exists

Description:

On container creation php artisan apiato:generate:container:
Generating Composer File
Container generated successfully.
Generating Composer File
Container already exists

Expected Behavior:

no error expected

Additional Context:

Versions:

  • Apiato Version: 10.0.0
  • PHP Version: 7.4.2

Steps To Reproduce:

  1. Create new container: php artisan apiato:generate:container
  2. Create new AppSection
    Last lines upon creation show:Capture

TestsAuthHelperTrait not returning User with roles

It happens that setupTestingUserAccess is not returning fresh copy of users with roles.

private function setupTestingUserAccess($user, $access = null)
{
$access = $access ? : $this->getAccess();
$user = $this->setupTestingUserPermissions($user, $access);
$user = $this->setupTestingUserRoles($user, $access);
return $user;
}

To make my test pass I had to change return $user; to return $user->fresh();

invoked route bug

Hi, you need to remove the namespace array item from Loaders\RoutesLoaderTrait.php in method getRouteGroup. Since you provide the wrong namespace, and actually it's a file path so it's a trigger bug. when I want in any route do this route::get('/test',TestCalls::class) it will throw this exception UnexpectedValueException : Invalid route action:
image

Api Version

Hi!, it is possible to disable a old api version?

then set a redirect to a set up or active version,

sample,
the http://me.com/v1/test is disabled, then it will redirect to http://me.com/v2/test

TestAuthHelperTrait does too much magic

I think createTestingUser method does too much magic behind the scenes.

For example this line I don't think this is the best idea... Now in real tests you have to call $this->actingAs($user,'web') in order to "disable" the linked line.

I expect the method to "create user" not "create and authenticate it". Or just make it protected so users (developers) can override.

Update to Laravel 10

Hello, I need to update laravel to v10 and already can not use apiato (require v9.x)
When can you update laravel version or help me pleade with use this package on v10.x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.