<commit_before><?php
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.phpdoctrine.com>.
 */
/**
 * Doctrine_Lib has not commonly used static functions, mostly for debugging purposes
 *
 * @package     Doctrine
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @category    Object Relational Mapping
 * @link        www.phpdoctrine.com
 * @since       1.0
 * @version     $Revision$
 * @author      <NAME> <<EMAIL>>
 */
class Doctrine_Lib
{
    /**
     * @param integer $state                the state of record
     * @see Doctrine_Record::STATE_* constants
     * @return string                       string representation of given state
     */
    public static function getRecordStateAsString($state)
    {
        switch ($state) {
            case Doctrine_Record::STATE_PROXY:
                return "proxy";
                break;
            case Doctrine_Record::STATE_CLEAN:
                return "persistent clean";
                break;
            case Doctrine_Record::STATE_DIRTY:
                return "persistent dirty";
                break;
            case Doctrine_Record::STATE_TDIRTY:
                return "transient dirty";
                break;
            case Doctrine_Record::STATE_TCLEAN:
                return "transient clean";
                break;
        }
    }
    /**
     * returns a string representation of Doctrine_Record object
     * @param Doctrine_Record $record
     * @return string
     */
    public static function getRecordAsString(Doctrine_Record $record)
    {
        $r[] = "<pre>";
        $r[] = "Component  : ".$record->getTable()->getComponentName();
        $r[] = "ID         : ".$record->obtainIdentifier();
        $r[] = "References : ".count($record->getReferences());
        $r[] = "State      : ".Doctrine_Lib::getRecordStateAsString($record->getState());
        $r[] = "OID        : ".$record->getOID();
        $r[] = "</pre>";
        return implode("\n",$r)."<br />";
    }
    /**
     * getStateAsString
     * returns a given connection state as string
     * @param integer $state        connection state
     */
    public static function getConnectionStateAsString($state)
    {
        switch ($state) {
            case Doctrine_Transaction::STATE_SLEEP:
                return "open";
                break;
            case Doctrine_Transaction::STATE_BUSY:
                return "busy";
                break;
            case Doctrine_Transaction::STATE_ACTIVE:
                return "active";
                break;
        }
    }
    /**
     * returns a string representation of Doctrine_Connection object
     * @param Doctrine_Connection $connection
     * @return string
     */
    public static function getConnectionAsString(Doctrine_Connection $connection)
    {
        $r[] = '<pre>';<commit_msg>Added getRecordAsXml that returns an record as XML. <commit_after><?php
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.phpdoctrine.com>.
 */
/**
 * Doctrine_Lib has not commonly used static functions, mostly for debugging purposes
 *
 * @package     Doctrine
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @category    Object Relational Mapping
 * @link        www.phpdoctrine.com
 * @since       1.0
 * @version     $Revision$
 * @author      <NAME> <<EMAIL>>
 */
class Doctrine_Lib
{
    /**
     * @param integer $state                the state of record
     * @see Doctrine_Record::STATE_* constants
     * @return string                       string representation of given state
     */
    public static function getRecordStateAsString($state)
    {
        switch ($state) {
        case Doctrine_Record::STATE_PROXY:
            return "proxy";
            break;
        case Doctrine_Record::STATE_CLEAN:
            return "persistent clean";
            break;
        case Doctrine_Record::STATE_DIRTY:
            return "persistent dirty";
            break;
        case Doctrine_Record::STATE_TDIRTY:
            return "transient dirty";
            break;
        case Doctrine_Record::STATE_TCLEAN:
            return "transient clean";
            break;
        }
    }
    /**
     * returns a string representation of Doctrine_Record object
     * @param Doctrine_Record $record
     * @return string
     */
    public static function getRecordAsString(Doctrine_Record $record)
    {
        $r[] = "<pre>";
        $r[] = "Component  : ".$record->getTable()->getComponentName();
        $r[] = "ID         : ".$record->obtainIdentifier();
        $r[] = "References : ".count($record->getReferences());
        $r[] = "State      : ".Doctrine_Lib::getRecordStateAsString($record->getState());
        $r[] = "OID        : ".$record->getOID();
        $r[] = "</pre>";
        return implode("\n",$r)."<br />";
    }

    public static function getRecordAsXml(Doctrine_Record $record, $xml = null)
    {
        $recordname = $record->getTable()->name;
        if ($xml == null) {
            $xml = new SimpleXMLElement("<" . $recordname . "></" . $recordname . ">");
        }
        $xml->addChild("id", $record->getOID());
        $xml_options = $record->option("xml");
        foreach ($record->getData() as $field => $value) {
            if (isset($xml_options["ignore_fields"]) && !in_array($field, $xml_options["ignore_fields"])) {
                $xml->addChild($field, $value);
            }
        }
        if (!isset($xml_options["include_relations"])) {
            return $xml->asXML();
        }
        $relations = $record->getTable()->getRelations();
        foreach ($relations as $name => $relation) {
            if (in_array($name, $xml_options["include_relations"])) {
                $relation_type = $relation->getType();
                $related_records = $record->get($name);
                if ($relation_type == Doctrine_Relation::ONE) {
                    $related_xml = $xml->addChild($name);
                    Doctrine_Lib::getRecordAsXml($related_records, $related_xml);
                } else {
                    $xml_collection = $xml->addChild($name . "s"); //this could be fixed to plurelize in some better way i guess
                    foreach ($related_records as $related_name => $related_record) {
                        $related_xml = $xml_collection->addChild($name);
                        Doctrine_Lib::getRecordAsXml($related_record, $related_xml);
                    }
                }
            }
        }
        return $xml->asXML();
    }


    /**
     * getStateAsString
     * returns a given connection state as string
     * @param integer $state        connection state
     */
    public static function getConnectionStateAsString($state)
    {
        switch ($state) {
        case Doctrine_Transaction::STATE_SLEEP:
            return "open";
            break;
        case Doctrine_Transaction::STATE_BUSY:
            return "busy";
            break;
        case Doctrine_Transaction::STATE_ACTIVE:
            return "active";
            break;
        }
    }
    /**
     * returns a string representation of Doctrine_Connection object
     * @param Doctrine_Connection $connection
     * @return string
     */
    public static function getConnectionAsString(Doctrine_Connection $connection)
    {
        $r[] = '<pre>';
{'fraction_non_alphanumeric': 0.10762823323103901, 'fraction_numerical': 0.00043840420868040335, 'mean_word_length': 2.2427149964463395, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 21}, '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': '6846339', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2349, 'n_words': 717}