Helper function for more readable check

@param string $state
@param mixed $overwrites
@return bool
194392
protected function getOverwriteValue($state, $overwrites)
    {
        if (is_array($overwrites) && array_key_exists($state, $overwrites)) {
            return $overwrites[$state];
        }
        return false;
    }
518514
public static function formatState($state)
    {
        return isset(self::$stateNames[$state]) ? self::$stateNames[$state] : $state;
    }
1357918
public function writeFile($overwrite = false) {
		$overwrite = ($this->type == self::TYPE_ENTITY) ? false : $overwrite;
		if (($this->existsFile() < self::FILE_MATCH) || $overwrite) {
			//$checkPath = dirname($this->getPath());
			if (@file_put_contents($this->getPath(), $this->getCode(), LOCK_EX)) {
				@chmod($this->getPath(), 0666);
				return true;
			}/* else {
				throw new Exception\PermissionException('Write access to Entity OR Model dirs denied');
			}*/
		}
		return false;
	}
542266
public function setState($state=0, $ids=array())
	{
		if (count($ids) <= 0)
		{
			return false;
		}

		$ids = array_map('intval', $ids);

		return $this->update()
			->set(array('state' => $state))
			->whereIn('id', $ids)
			->execute();
	}
214189
public function set_state($state) {
        if ($state <= $this->state) {
            return false;
        }
        $this->state = $state;
        return true;
    }
925766
public function set_excluded($state) {
        if (empty($this->excluded) and $state) {
            $this->excluded = time();
            $this->update();
            return true;

        } else if (!empty($this->excluded) and !$state) {
            $this->excluded = 0;
            $this->update();
            return true;
        }
        return false;
    }
485610
protected function parseStates(array $states)
    {
        $newStates = array();
        foreach ($states as $key => $state) {
            if (null === $state) {
                $newStates[] = $key;
            } elseif (self::CFG_STATE_DISABLE !== $state) {
                $newStates[] = $state;
            } elseif (null !== $index = array_search($key, $newStates)) {
                unset($newStates[$index]);
            }
        }

        return $newStates;
    }
1269902
public function tokenize($state)
    {
        $rules = $this->ruler->getRules('');
        $len = count($rules);
        $end = $state->posMax;
        $maxNesting = $state->md->options->maxNesting;
        $ok = false;

        $i = 0;
        while ($state->pos < $end) {
            // Try all possible rules.
            // On success, rule should:
            //
            // - update `state.pos`
            // - update `state.tokens`
            // - return true
            if($state->pos == 3){
                $test = 0;
            }else if($state->pos == 17){
                $test = 0;
            }

            if ($state->level < $maxNesting) {
                $i = 0;
                foreach ($rules as &$rule) {
                    $i++;
                    if( is_array($rule) )
                        $ok = $rule[0]->{$rule[1]}($state, false);
                    else
                        $ok = $rule($state, false);
                    if ($ok) { break; }
                }
            }

            if ($ok) {
                if ($state->pos >= $end) { break; }
                continue;
            }

            $state->pending .= $state->src[$state->pos++];
        }

        if ($state->pending) {
            $state->pushPending();
        }
    }
6009
public final function enable($state = true){

		$old_state = $this->_enabled;

		$this->_enabled = (bool) $state;

		return $old_state;
	}
1160268
public function switchTo($state)
    {
        $states = [
            0,
            1,
            false,
            true,
            'on',
            'off',
            'yes',
            'no'
        ];

        if (!in_array($state, $states)) {
            Throw new ControlException('Wrong state for on/off switch.');
        }

        switch ($state) {
            case 0:
            case false:
            case 'off':
            case 'no':
                $this->switchOff();
                break;
            case 1:
            case true:
            case 'on':
            case 'yes':
                $this->switchOn();
                break;
        }
    }
1367718
public function copy(string $destination, $overwrite = false) : bool
    {
        $copied = false;

        if ($this->isFile()) {
            $exists = file_exists($destination);
            if (!$exists || ($exists && $overwrite)) {
                $copied = copy($this->realPath, $destination);
            }
        }

        return $copied;
    }
490678
public function extractManipulationWriteState(&$writes)
    {
        $self = get_class($this);
        $tableName = DataObject::getSchema()->tableName(Subsite::class);
        $query = SQLSelect::create('"ID"', '"' . $tableName . '"');
        $subsites = array_merge(['0'], $query->execute()->column());

        foreach ($writes as $key => $write) {
            $applies = $this->appliesTo($write['class'], true);
            if (!$applies) {
                continue;
            }

            if (isset($write['fields'][SiteTree::class . ':SubsiteID'])) {
                $subsitesForWrite = [$write['fields'][SiteTree::class . ':SubsiteID']];
            } elseif (isset($write['fields'][File::class . ':SubsiteID'])
                && (int) $write['fields'][File::class . ':SubsiteID'] !== 0
            ) {
                // files in subsite 0 should be in all subsites as they are global
                $subsitesForWrite = [$write['fields'][File::class . ':SubsiteID']];
            } else {
                $subsitesForWrite = $subsites;
            }

            $next = [];
            foreach ($write['statefulids'] as $i => $statefulid) {
                foreach ($subsitesForWrite as $subsiteID) {
                    $next[] = [
                        'id' => $statefulid['id'],
                        'state' => array_merge(
                            $statefulid['state'],
                            [$self => (string) $subsiteID]
                        ),
                    ];
                }
            }
            $writes[$key]['statefulids'] = $next;
        }
    }
217046
public function checkState($storeState, $state = null)
	{
		if(null === $state)
		{
			if(null === $this->state)
			{
				if(isset($_GET['state']))
				{
					$state = $_GET['state'];
				}
				else
				{
					$state = '';
				}
			}
			else
			{
				$state = $this->state;
			}
		}
		return $storeState === $state;
	}
1352383
public function encodeFile( $fileName, $overwrite = FALSE )
	{
		if( !file_exists( $fileName ) )
			return FALSE;
		if( $this->isEncoded( $fileName ) )
			return TRUE;
		$php		= FS_File_Reader::load( $fileName );
		$code		= $this->encode( $php );
		$dirname	= dirname( $fileName );
		$basename	= basename( $fileName );
		$target		= $dirname."/".$this->filePrefix.$basename.$this->fileSuffix;
		if( $fileName == $target && !$overwrite )
			throw new RuntimeException( 'File cannot be overwritten, use Parameter "overwrite".' );
//		copy( $fileName, "#".$fileName );
		return (bool) FS_File_Writer::save( $target, $code );
	}
194042
protected function isRedirectState($state)
	{
		$state = (int) $state;

		return $state > 299 && $state < 400 && array_key_exists($state, $this->responseMap);
	}
832177
public function copyFiles($files, $overwrite = null)
    {
        /*
         * To allow for manual override on the overwriting flag, we check to see if
         * the $overwrite flag was set and is a boolean value.  If not, use the object
         * allowOverwrite flag.
         */

        if (is_null($overwrite) || !is_bool($overwrite))
        {
            $overwrite = $this->overwrite;
        }

        $config = array();

        /*
         * $files must be an array of filenames.  Verify that it is an array with
         * at least one file to copy.
         */
        if (is_array($files) && count($files) > 0)
        {
            foreach ($files as $file)
            {
                // Get the source and destination paths
                $filesource = JPath::clean($file['src']);
                $filedest = JPath::clean($file['dest']);
                $filetype = array_key_exists('type', $file) ? $file['type'] : 'file';

                $config[$this->relativeTargetPath($filedest)] = $this->relativeJoomlaTargetPath($filedest);

                $filedestCopy = $this->rewriteTargetPath($filedest);
                $filedestCopyContainer = dirname($filedestCopy);

                if (!file_exists(dirname($filedest))) {
                    mkdir(dirname($filedest), 0777, true);
                }

                if (!file_exists($filesource))
                {
                    /*
                     * The source file does not exist.  Nothing to copy so set an error
                     * and return false.
                     */
                    JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_NO_FILE', $filesource), JLog::WARNING, 'jerror');

                    return false;
                }
                elseif (($exists = file_exists($filedest)) && !$overwrite)
                {
                    // It's okay if the manifest already exists
                    if ($this->getPath('manifest') == $filesource)
                    {
                        continue;
                    }

                    // The destination file already exists and the overwrite flag is false.
                    // Set an error and return false.
                    JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_FILE_EXISTS', $filedest), JLog::WARNING, 'jerror');

                    return false;
                }
                else
                {
                    // Copy the folder or file to the new location.
                    if ($filetype == 'folder')
                    {
                        if (!(JFolder::copy($filesource, $filedest, null, $overwrite))) {
                            JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FOLDER', $filesource, $filedest), JLog::WARNING, 'jerror');

                            return false;
                        }

                        if (!is_dir($filedestCopyContainer)) {
                            mkdir($filedestCopyContainer, 0775, true);
                        }

                        if (!(JFolder::copy($filedest, $filedestCopy, null, $overwrite))) {
                            JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FOLDER', $filedest, $filedestCopy), JLog::WARNING, 'jerror');

                            return false;
                        }

                        $step = array('type' => 'folder', 'path' => $filedest);
                    }
                    else
                    {
                        if (!(JFile::copy($filesource, $filedest, null))) {
                            JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FILE', $filesource, $filedest), JLog::WARNING, 'jerror');

                            // In 3.2, TinyMCE language handling changed.  Display a special notice in case an older language pack is installed.
                            if (strpos($filedest, 'media/editors/tinymce/jscripts/tiny_mce/langs'))
                            {
                                JLog::add(JText::_('JLIB_INSTALLER_NOT_ERROR'), JLog::WARNING, 'jerror');
                            }

                            return false;
                        }

                        if (!is_dir($filedestCopyContainer)) {
                            mkdir($filedestCopyContainer, 0775, true);
                        }

                        if (!(JFile::copy($filedest, $filedestCopy, null))) {
                            JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FILE', $filedest, $filedestCopy), JLog::WARNING, 'jerror');

                            return false;
                        }

                        $step = array('type' => 'file', 'path' => $filedest);
                    }

                    /*
                     * Since we copied a file/folder, we want to add it to the installation step stack so that
                     * in case we have to roll back the installation we can remove the files copied.
                     */
                    if (!$exists)
                    {
                        $this->stepStack[] = $step;
                    }
                }
            }
        }
        else
        {
            // The $files variable was either not an array or an empty array
            return false;
        }

        self::$assetInstaller->addToConfig($config);
        self::$assetInstaller->install();

        return count($files);
    }
1351515
public void addOverwriteProperties(State state) {
    Map<String, String> propsMap = Maps.newHashMap();
    for (String key : state.getPropertyNames()) {
      propsMap.put(key, state.getProp(key));
    }
    addOverwriteProperties(propsMap);
  }