Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/Ecombricks/Inventory/Framework/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/Ecombricks/Inventory/Framework/SourceTrait.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See LICENSE.txt for license details.
 */
namespace Ecombricks\Inventory\Framework;

/**
 * Source trait
 */
trait SourceTrait
{
    
    /**
     * Source code
     * 
     * @var string
     */
    protected $sourceCode;
    
    /**
     * Source object keys
     * 
     * @var array
     */
    protected $sourceObjectKeys;
    
    /**
     * Source objects
     * 
     * @var array
     */
    protected $sourceObjects;
    
    /**
     * Check if object can accept source code
     * 
     * @param object $object
     * @return bool
     */
    public function canObjectAcceptSourceCode($object)
    {
        return $object && is_object($object) && method_exists($object, 'setSourceCode');
    }
    
    /**
     * Copy source code
     * 
     * @param object $object
     * @param string $sourceCode
     * @return $this
     */
    public function copySourceCode($object, $sourceCode)
    {
        if ($this->canObjectAcceptSourceCode($object)) {
            $object->setSourceCode($sourceCode);
        }
        return $this;
    }
    
    /**
     * Set source code
     * 
     * @param string $sourceCode
     * @return $this
     */
    public function setSourceCode($sourceCode)
    {
        if ($this->sourceCode == $sourceCode) {
            return $this;
        }
        $this->beforeSetSourceCode($sourceCode);
        $this->sourceCode = $sourceCode;
        foreach ($this->getSourceObjects() as $object) {
            $this->copySourceCode($object, $sourceCode);
        }
        $this->afterSetSourceCode($sourceCode);
        return $this;
    }
    
    /**
     * Before set source code
     * 
     * @param string $sourceCode
     * @return $this
     */
    public function beforeSetSourceCode($sourceCode)
    {
        return $this;
    }
    
    /**
     * After set source code
     * 
     * @param string $sourceCode
     * @return $this
     */
    public function afterSetSourceCode($sourceCode)
    {
        return $this;
    }
    
    /**
     * Get source code
     * 
     * @return int
     */
    public function getSourceCode()
    {
        return $this->sourceCode;
    }
    
    /**
     * Unset source code
     * 
     * @return $this
     */
    public function unsSourceCode()
    {
        $this->sourceCode = null;
        return $this;
    }
    
    /**
     * Get source object keys
     * 
     * @return array
     */
    public function getSourceObjectKeys()
    {
        if ($this->sourceObjectKeys !== null) {
            return $this->sourceObjectKeys;
        }
        $this->sourceObjectKeys = array_keys(get_object_vars($this));
        return $this->sourceObjectKeys;
    }
    
    /**
     * Get source objects
     * 
     * @return array
     */
    public function getSourceObjects()
    {
        if ($this->sourceObjects !== null) {
            return $this->sourceObjects;
        }
        $objects = [];
        $objectKeys = $this->getSourceObjectKeys();
        if (empty($objectKeys)) {
            $this->sourceObjects = [];
            return $this->sourceObjects;
        }
        foreach ($objectKeys as $objectKey) {
            if (empty($this->$objectKey)) {
                continue;
            }
            $object = $this->$objectKey;
            if (!$this->canObjectAcceptSourceCode($object)) {
                continue;
            }
            $objects[$objectKey] = $object;
        }
        $this->sourceObjects = $objects;
        return $this->sourceObjects;
    }
    
}

Spamworldpro Mini