ajthinking / archetype Goto Github PK
View Code? Open in Web Editor NEWEdit PHP files programmatically
Edit PHP files programmatically
I'd like to add a new line at the end of the section array with 'key3' => 'value3'
. How can I do ?
<?php
return [
'section' => [
'key1' => 'value1',
'key2' => 'value2',
],
Thanx
Base Laravel 6.2 installation with php-file-manipulator.
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
composer dump-autoload
php artisan storage:link
You can use the file below to read grouped imports.
but manipulating them is another matter.
https://github.com/imanghafoori1/laravel-microscope/blob/master/src/Analyzers/ParseUseStatement.php
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?
Hi, when using PHPFile, is there a way to add methods to a class?
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!
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']);
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.
This package does not yet support PHP 8 features. Would love some help with this
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
Hi, i want use your package for development another laravel package.
My use case :
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
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]);
Help wanted
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.
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.
packages/archetype
).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:
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?)
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.