Giter VIP home page Giter VIP logo

php-stub-generator's Introduction

php-stub-generator

A tool to generate stub-files for your php classes.

The main purpose for this tool is to generate stub-files from php classes to have code completion for your IDE when encrypting your library with e.g. the ioncube encoder.

Minimum PHP Version License

Installation

A basic installation via Composer could be done this way:

composer require setasign/php-stub-generator

Composer will install the tool to your project's vendor/setasign/php-stub-generator directory.

Basic usage

<?php
declare(strict_types=1);

use setasign\PhpStubGenerator\PhpStubGenerator;
use setasign\PhpStubGenerator\Reader\AllFiles;

require_once __DIR__ . '/vendor/autoload.php';

$generator = new PhpStubGenerator();
$generator->addSource(
    'setapdf-core',
    new AllFiles(__DIR__ . '/vendor/setasign/setapdf-core/library')
);
$output = $generator->generate();

file_put_contents(__DIR__ . '/setapdf-core-stub.php', $output);

Alternatively you could just call the cli helper.

vendor/bin/php-stub-generator generate setapdf-core/library setapdf-core-stub.php

Settings

The PhpStubGenerator class has following settings:

class PhpStubGenerator
{
    /**
     * End of line character(s).
     *
     * Doesn't change the used EOL character(s) of doc blocks.
     *
     * @var string
     */
    public static $eol = "\n";

    /**
     * Tab character(s)
     *
     * @var string
     */
    public static $tab = '    ';

    /**
     * If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1)
     * 
     * Within the cli tool can be set with the option "--addClassConstantsVisibility"
     * 
     * @var bool
     */
    public static $addClassConstantsVisibility = false;
}

Drawbacks / TODOs

  • Traits are not supported yet and probably won't be because of bugs like this. The actual reflection api doesn't give enough information to rebuild the conflict resolution block. Additionally the "declaring class" of imported trait methods is the importing class and not like expected the trait.
  • Calculated constants or constants that use other constants like __DIR__ will be filled with the values of the runtime environment.

php-stub-generator's People

Contributors

maximiliankresse avatar peter279k avatar szepeviktor 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

Watchers

 avatar  avatar  avatar  avatar

php-stub-generator's Issues

5.6 incompatibilities

I need to generate stubs for an application that was encoded with ioncube for 5.6, and since ioncube is a snowflake, ioncube 7.1 cant load files encoded files for 5.6 and your library doesnt support 5.6. Could it be possible to allow this backwards compatibility.

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.