<commit_before><?php
/**
 * PHP patterns
 * Copyleft (c) 2013 <NAME> and contributors
 * <www.ateliers-pierrot.fr> - <<EMAIL>>
 * License GPL-3.0 <http://www.opensource.org/licenses/gpl-3.0.html>
 * Sources <https://github.com/atelierspierrot/patterns>
 */

namespace Patterns\Abstracts;

use Patterns\Interfaces\StaticCreatorInterface;

/**
 * @author      <NAME> <<EMAIL>>
 */
abstract class AbstractStaticCreator implements StaticCreatorInterface
{

    /**
     * Force any descendant to implement a constructor as it will be called by the `create()`  static method
     */
    abstract public function __construct();
    
    /**
     * @return self Must return a new instance of the object created with function arguments
     */
    public static function create()
    {
        $_cls = get_called_class();
        $_obj = call_user_func_array(array($_cls, '__construct'), func_get_args());
        return $_obj;
    }
    
}

// Endfile<commit_msg>The new static construction helper<commit_after><?php
/**
 * PHP patterns
 * Copyleft (c) 2013 <NAME> and contributors
 * <www.ateliers-pierrot.fr> - <<EMAIL>>
 * License GPL-3.0 <http://www.opensource.org/licenses/gpl-3.0.html>
 * Sources <https://github.com/atelierspierrot/patterns>
 */

namespace Patterns\Abstracts;

use Patterns\Interfaces\StaticCreatorInterface;

/**
 * This class allows to create objects that can be statically created "on-the-fly" to allow
 * method chaining constructing them like:
 *
 *     $obj = ObjectStaticCreator::create( arguments )
 *         ->method();
 *
 * This logic is implemented thru a required `init()` method in children class that will be called
 * on static creation (in non-static env) and by constructor.
 *
 * @author      <NAME> <<EMAIL>>
 */
abstract class AbstractStaticCreator implements StaticCreatorInterface
{

    /**
     * Force any descendant to implement a special constructor `init()` as it will be called by the `create()`  static method
     */
    abstract public function init();
    
    /**
     * Magic default constructor for non-static use
     *
     * This may use the same arguments as the `init()` method.
     */
    public function __construct()
    {
        call_user_func_array(array($this, 'init'), func_get_args());
    }
    
    /**
     * Static creation of the object
     *
     * This may use the same arguments as the `init()` method.
     *
     * @return self Must return a new instance of the object created with function arguments
     */
    public static function create()
    {
        $_cls = get_called_class();
        $_obj = new $_cls;
        call_user_func_array(array($_obj, 'init'), func_get_args());
        return $_obj;
    }
    
}

// Endfile
{'fraction_non_alphanumeric': 0.11586715867158671, 'fraction_numerical': 0.005904059040590406, 'mean_word_length': 2.9750733137829912, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1078618', 'n_tokens_mistral': 801, 'n_tokens_neox': 779, 'n_words': 244}