Coder Social home page Coder Social logo

archetype's Introduction

archetype's People

Contributors

ajthinking avatar dependabot[bot] avatar imanghafoori1 avatar jackmcdade avatar kakposoe avatar ordago avatar septio avatar seryak avatar worldseso7 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  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

archetype's Issues

Project fails to load files

setup:

Base Laravel 6.2 installation with php-file-manipulator.

error description:

When trying to load in files with the documented example PHPFile::in('database/migrations') php-file-manipulator instantly fails with the following error message:
Illuminate/Contracts/Filesystem/FileNotFoundException with message '/Code/database/migrations/SomeFile.php

What I've tried:

  1. composer dump-autoload
  2. checked folder permissions
  3. reinstalled php-file-manipulator
  4. php artisan storage:link

Setting class definitions and using constants in property values

Hey there, is there any possible way to set class properties without having Archetype modify what we're passing? For example, we're trying to build some fairly elaborate Laravel Artisan generators and want to programmatically update a ServiceProvider, but can't wrap my brain around the ASTQueryBuilder stuff. Here's example of what I'm trying to inject into an empty class stub:

protected $fieldtypes = [
    Fieldtypes\YourFieldtype::class,
];

protected $scripts = [
    __DIR__.'/../dist/js/addon.js',
];

The problem is Fieldtypes\YourFieldtype::class, becomes a string, as does __DIR__. We could use a string version of the classname, but if a user already has a $fieldtypes property with another class in there the parser breaks.

Here's how I've attempted to solve it:

PHPFile::load('addons/rad-city/knight-rider/src/ServiceProvider.php')
        ->add()->protected()->property('fieldtypes', 'Radcity\KnightRider\Fieldtypes\KnightRider')
        ->add()->protected()->property('scripts', __DIR__.'/../dist/js/addon.js')
        ->save();

Thoughts? Not possible?

Add return parent::method() to class body

My use case is to make the following:

public function myMethod() : self
{
	return parent::myMethod();
}

But I'm struggling with the proper stmt and BuilderFactory.

Do you have any input on this?

Thanks a lot!

Rewrite StmtInserter

The method insertStmts method automatically sorts the nodes in a strange way.
Typically using ->add() will prepend the node among its equals. So the new use statement below will come out in the top:

PHPFile::load(User::class)
    ->add()->use(['Add\This']);

Improvements

  • ability to bypass automatic sorting (for example put properties AFTER methods if you for some reason want to)
  • ability to prepend and push among equals
  • sorting styles (by length, alphabetically)

Composer 2 PSR-4 Autoloading Conflict

The file src/Schema/SimpleSchema/Directives/Float.php containing class FloatDirective is named differently from the class name.

This conflicts with PS4 autoloading name conventions, as a result the package being skipped when dumping the autoload.

PHP 8 Support

This package does not yet support PHP 8 features. Would love some help with this

running phpunit tests

I forked this to see if I could figure out a way to use it Symfony, and the first thing I did was run composer install and then try to run the tests.

How should tests be run?

endor/bin/phpunit 
PHP Fatal error:  Uncaught Error: Call to undefined function describe() in /home/tac/g/tacman/archetype/tests/Unit/Facades/PHPFileTest.php:10
Stack trace:
#0 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once()
#1 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load()
#2 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/Framework/TestSuite.php(397): PHPUnit\Util\FileLoader::checkAndLoad()
#3 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/Framework/TestSuite.php(536): PHPUnit\Framework\TestSuite->addTestFile()
#4 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/TextUI/TestSuiteMapper.php(67): PHPUnit\Framework\TestSuite->addTestFiles()
#5 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/TextUI/Command.php(389): PHPUnit\TextUI\TestSuiteMapper->map()
#6 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/TextUI/Command.php(112): PHPUnit\TextUI\Command->handleArguments()
#7 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/TextUI/Command.php(97): PHPUnit\TextUI\Command->run()
#8 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()
#9 /home/tac/g/tacman/archetype/vendor/bin/phpunit(122): include('...')
#10 {main}

Next PHPUnit\TextUI\RuntimeException: Call to undefined function describe() in /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/TextUI/Command.php:99
Stack trace:
#0 /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()
#1 /home/tac/g/tacman/archetype/vendor/bin/phpunit(122): include('...')
#2 {main}
  thrown in /home/tac/g/tacman/archetype/vendor/phpunit/phpunit/src/TextUI/Command.php on line 9

Getter & Setter for class constants

Hi, i want use your package for development another laravel package.
My use case :

  • When installing my package, reading app/Providers/RouteServiceProvider.php and change value for constant 'HOME'.

But i dont see any methods from PHPFile for changing class constant. Can you please answer is a missing feature in your package ?

Also, i forked your package, and create Archetype\Endpoints\PHP\Constant with same methods as Archetype\Endpoints\PHP\Property (read value from constant by key, set value, create constant if not exist). If you want i can send Pull Request, but my code is need check and fix, because i dont understanding completely how working nikic\phpparser

Add traitUse()

The ability to get/set which traits a class uses is currently missing.

Consider:

class X
{
    use TraitA, TraitB, TraitC;
    use TraitD;
    use TraitE;
}

The variations of how these are grouped poses some questions. What/How should the following return/manipulate?

    PHPFile::load(X::class)->useTrait();
    PHPFile::load(X::class)->add()->useTrait(F::class);
    PHPFile::load(X::class)->set()->useTrait([New1::class, New2::class]);    

Using testbench package for testing

Hey,

I have been wanting this exact package but i have a limited understanding
of both how nikic/php-parser works and abstract syntax tree.

Thank you for creating this.

I wanted to make a simple PR #16 but it looks like it broke something in the tests.

My question is regarding how the tests for this package is setup.

  • You currently you have to create a "host" Laravel project, then clone this repo
    inside that project (eg. packages/archetype).
  • The tests rely on the the "host" Laravel project's files to run.

I don't know if you are aware of this package orchestral/testbench.

"Laravel Testing Helper for Packages Development".

I believe this package can simplify the setup:

  • no need to create/manage a "host" Laravel project.
  • easily register providers and aliases
protected function getPackageProviders($app)
{
   return [
       \Archetype\ServiceProvider::class,
   ];
}
protected function getPackageAliases($app)
{
   return [
       'PHPFile' => \Archetype\Facades\PHPFile::class,
       'LaravelFile' => \Archetype\Facades\LaravelFile::class
   ];
}

If you are aware of this package, is there a reason you chose not to use it and would you consider using it? (limitations, personal preference)

If you are not aware of this package, would you consider using it? (pr welcome?)

Document how to use in a Symfony project

I'd love to be able to use this in a Symfony project. If you have the symfony CLI installed, here's a simple script to see the error. (I'm only putting the example in the controller to make it easier to see the error message). Since it's not lavarel, I also installed illuminate/support.

Thanks.

symfony new --webapp archetype-test && cd archetype-test
composer install
composer require ajthinking/archetype illuminate/support 
cat > src/Controller/AppController.php <<'END'
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Archetype\Facades\PHPFile;

class AppController extends AbstractController
{
    #[Route('/', name: 'app_homepage')]
    public function index()
    {

// Create new class
        PHPFile::make()->class('App\\Entity\\Product')
            ->use('Shippable')
            ->public()->property('stock', -1)
            ->save();
    }
}
END

symfony server:start -d
symfony open:local

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.