<commit_before><?php

namespace Ornament;

use StdClass;
use ReflectionClass;
use ReflectionProperty;

/**
 * A container is a simple internal object representation of (part of) a model.
 */
class Container
{
    private $adapter;
    private $lastCheck = [];

    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->lastCheck = $this->export();
    }

    /**
     * Query multiple models in an Adapter-independent way.
     *
     * @param object $parent The actual parent model to load into.
     * @param array $parameters Key/value pair of parameters to query on (e.g.,
     *                          ['parent' => 1]).
     * @param array $opts Optional hash of options.
     * @return array Array of models of the same type as $parent.
     */
    public function query($parent, array $parameters, array $opts = [])
    {
        return $this->adapter->query($parent, $parameters, $opts);
    }

    /**
     * (Re)load the model based on existing settings.
     */
    public function load()
    {
        $this->adapter->load($this);
    }

    /**
     * Persist this model back to whatever storage Adapter it was constructed
     * with.
     *
     * @return boolean true on success, false on error.
     */
    public function save()
    {
        if ($this->isNew()) {
            return $this->adapter->create($this);
        } else {
            return $this->adapter->update($this);
        }
    }

    /**
     * Delete this model from whatever storage Adapter it was constructed with.
     *
     * @return boolean true on success, false on error.
     */
    public function delete()
    {
        return $this->adapter->delete($this);
    }

    /**
     * Internal helper method to export the model's public properties.
     *
     * @return array An array of key/value pairs.
     */
    private function export()
    {
        $ref = new ReflectionClass($this);
        $exported = new StdClass;
        foreach ($ref->getProperties(ReflectionProperty::IS_PUBLIC) as $prop) {
            $exported->{$prop->name} = $this->{$prop->name};
        }
        return $exported;
        $o = $this;
        return call_user_func(function () use ($o) {
            return get_object_vars($o);
        });
    }

    /**
     * Marks this model as being "new" (i.e., save proxies to create, not
     * update).
     */
    public function markNew()
    {
        $this->lastCheck = [];
    }

    /**
     * Marks this model as "deleted". The class will still contain old
     * properties and values, but deletion has taken place.
     */
    public function markDeleted()
    {
        $this->lastCheck = null;
    }

    /**
     * Marks this model as "clean", i.e. set clean state to current state,
     * no questions asked.
     *
     * @see Ornament\Storage::markClean
     */
    public function markClean()
    {
        $this->lastCheck = $this->export();<commit_msg>export better... pfff<commit_after><?php

namespace Ornament;

use StdClass;
use ReflectionProperty;

/**
 * A container is a simple internal object representation of (part of) a model.
 */
class Container
{
    private $adapter;
    private $lastCheck = [];

    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->lastCheck = $this->export();
    }

    /**
     * Query multiple models in an Adapter-independent way.
     *
     * @param object $parent The actual parent model to load into.
     * @param array $parameters Key/value pair of parameters to query on (e.g.,
     *                          ['parent' => 1]).
     * @param array $opts Optional hash of options.
     * @return array Array of models of the same type as $parent.
     */
    public function query($parent, array $parameters, array $opts = [])
    {
        return $this->adapter->query($parent, $parameters, $opts);
    }

    /**
     * (Re)load the model based on existing settings.
     */
    public function load()
    {
        $this->adapter->load($this);
    }

    /**
     * Persist this model back to whatever storage Adapter it was constructed
     * with.
     *
     * @return boolean true on success, false on error.
     */
    public function save()
    {
        if ($this->isNew()) {
            return $this->adapter->create($this);
        } else {
            return $this->adapter->update($this);
        }
    }

    /**
     * Delete this model from whatever storage Adapter it was constructed with.
     *
     * @return boolean true on success, false on error.
     */
    public function delete()
    {
        return $this->adapter->delete($this);
    }

    /**
     * Internal helper method to export the model's public properties.
     *
     * @return array An array of key/value pairs.
     */
    private function export()
    {
        $exported = new StdClass;
        foreach ($this as $name => $field) {
            if ((new ReflectionProperty($this, $name))->isPublic()) {
                $exported->$name = "$field";
            }
        }
        return $exported;
    }

    /**
     * Marks this model as being "new" (i.e., save proxies to create, not
     * update).
     */
    public function markNew()
    {
        $this->lastCheck = [];
    }

    /**
     * Marks this model as "deleted". The class will still contain old
     * properties and values, but deletion has taken place.
     */
    public function markDeleted()
    {
        $this->lastCheck = null;
    }

    /**
     * Marks this model as "clean", i.e. set clean state to current state,
     * no questions asked.
     *
     * @see Ornament\Storage::markClean
     */
    public function markClean()
    {
        $this->lastCheck = $this->export();
{'fraction_non_alphanumeric': 0.1220828979449669, 'fraction_numerical': 0.00034831069313827936, 'mean_word_length': 1.9927045336112559, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2801517', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1583, 'n_words': 521}