PHP code example of rougin / classidy

1. Go to this page and download the library: Download rougin/classidy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rougin / classidy example snippets

 bash
$ php index.php



namespace Acme;

/**
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet
{
    public function greet()
    {
        return 'Hello world!';
    }
}
 php
// index.php

// ...

$shout = false;

$method->setCodeLine(function ($lines) use ($shout)
{
    if ($shout)
    {
        $lines[] = "return 'HELLO WORLD!';";
    }
    else
    {
        $lines[] = "return 'Hello world!';";
    }

    return $lines;
});

// ...
 php
// index.php

use Acme\Hello\Greeter;

// ...

// Define the details of the class ---
// ...

$class->extendsTo(Greeter::class);

// ...
// -----------------------------------

// ...
 bash
$ php index.php



namespace Acme;

use Acme\Hello\Greeter;

/**
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet extends Greeter
{
    public function greet()
    {
        return 'Hello world!';
    }
}
 bash
$ php index.php



namespace Acme;

use Acme\Hello\Greeter;

/**
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet extends Greeter implements Greetable, Helloable
{
    public function greet()
    {
        return 'Hello world!';
    }
}
 php
// index.php

use Acme\Hello\Traitable;

// ...

// Define the details of the class ---
// ...

$class->addTrait(Traitable::class);

// ...
// -----------------------------------

// ...
 bash
$ php index.php



namespace Acme;

use Acme\Hello\Traitable;

/**
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet
{
    use Traitable;

    public function greet()
    {
        return 'Hello world!';
    }
}
 php
// index.php

// ...

// Add a "greet" method in the class ---
$method = new Method('greet');
$method->setCodeEval(function ()
{
    return 'Hello world!';
});
$class->addMethod($method);
// -------------------------------------

// ...
 php
// index.php

// ...

$method = new Method('greet');
$method->addBooleanArgument('shout')
    ->withDefaultValue(false);
$method->setReturn('string');
$method->setCodeEval(function ()
{
    return 'Hello world!';
});
$class->addMethod($method);

// ...
 bash
$ php index.php



namespace Acme;

use Acme\Hello\Greeter;

/**
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet extends Greeter implements Greetable, Helloable
{
    /**
     * @param boolean $shout
     *
     * @return string
     */
    public function greet($shout = false)
    {
        return 'Hello world!';
    }
}
 php
// index.php

// ...

$method = new Method('greet');
$method->addClassArgument('test', 'Acme\Test')
    ->withoutTypeDeclared();
$method->setReturn('string');
$method->setCodeEval(function ($test)
{
    return $test->hello();
});
$class->addMethod($method);

// ...
 bash
$ php index.php



namespace Acme;

use Acme\Hello\Greeter;

/**
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet extends Greeter implements Greetable, Helloable
{
    /**
     * @param \Acme\Test $test
     *
     * @return string
     */
    public function greet($test)
    {
        return $test->hello();
    }
}
 php
// index.php

// ...

$method = new Method('greet');

// Set the method as "protected" ---
$method->asProtected();
// ---------------------------------

// Set the method as "private" ---
$method->asPrivate();
// -------------------------------

// ...
 php
// index.php

// ...

$method = new Method('greet');

// ...

// Set as "@method" in the class ---
$method->asTag();
// ---------------------------------

// ...
 bash
$ php index.php



namespace Acme;

use Acme\Hello\Greeter;

/**
 * Sample class for Acme.
 *
 * @method string greet(boolean $shout = false)
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet extends Greeter implements Greetable, Helloable
{
}
 php
// index.php

// ...

$class->addStringProperty('text')
    ->withDefaultValue('Hello world!');

// ...

// Modify "greet" method to access "text" property ---
$method->setCodeEval(function ()
{
    return $this->text;
});
// ---------------------------------------------------

// ...
 php
$ php index.php



namespace Acme;

use Acme\Hello\Greeter;

/**
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet extends Greeter implements Greetable, Helloable
{
    /**
     * @var string
     */
    protected $text = 'Hello world!';

    /**
     * @param boolean $shout
     *
     * @return string
     */
    public function greet($shout = false)
    {
        return $this->text;
    }
}
 php
// index.php

// ...

$class->addStringProperty('text')
    ->asPrivate()
    ->withDefaultValue('Hello world!');

// ...
 php
// index.php

// ...

$class->addStringProperty('text')->asTag();

// ...
 bash
$ php index.php



namespace Acme;

use Acme\Hello\Greeter;

/**
 * @property string $text
 *
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet extends Greeter implements Greetable, Helloable
{
}
 php
// index.php

// ...

$class->setEmpty();

// ...
 php
$ php index.php



namespace Acme;

use Acme\Hello\Greeter;

/**
 * Sample class for Acme.
 *
 * @package Acme
 *
 * @author John Doe <[email protected]>
 */
class Greet extends Greeter implements Greetable, Helloable
{
}