Save data to log file

@param string $data
@param string $fileName
@param bool $override
963154
protected function saveLog($data, $fileName, $override = false)
    {
        file_put_contents($this->directory . DIRECTORY_SEPARATOR . $fileName,
            $data, $override ? 0 : FILE_APPEND);
    }
608929
protected function filePutContents(string $fileName, string $data): bool
    {
        return (bool)@file_put_contents($fileName, $data);
    }
825248
protected function _encodeFile( $fileName, $data )
    {
        $_filePath = dirname( $fileName );

        if ( !is_dir( $_filePath ) )
        {
            if ( false === @mkdir( $_filePath, 0777, true ) && !is_dir( $_filePath ) )
            {
                return false;
            }
        }
        elseif ( !is_writable( $_filePath ) )
        {
            return false;
        }

        $_tempFile = tempnam( $_filePath, basename( $fileName ) );

        if ( false !== file_put_contents( $_tempFile, json_encode( $data ) ) && @rename( $_tempFile, $fileName ) )
        {
            @chmod( $fileName, 0666 & ~umask() );

            return true;
        }

        return false;
    }
763036
protected function add(Permission $permission, $override = true)
    {
        if ($override || ! $this->permissions->containsKey($permission->getName()))
        {
            $this->permissions->set($permission->getName(), $permission);
        }
    }
1346508
public function upload($source, $path, $override = false)
    {
        $path = trim($path, '/');
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $type  = finfo_file($finfo, $source);
        finfo_close($finfo);

        $response = $this->clientS3->putObject(array(
            'Bucket'      => $this->bucket,
            'Key'         => $path,
            'SourceFile'  => $source,
            'ACL'         => static::ACL_PUBLIC_READ,
            'ContentType' => $type,
            'CacheControl' => "max-age={$this->expires_seconds}",
            'Expires' => gmdate("D, d M Y H:i:s T", time()+$this->expires_seconds),
        ));

        return true;
    }
938701
private function loadFromFile($filename, $overwrite = false)
    {
        try {
            $yamlDatas = Yaml::parse(file_get_contents($filename));

            if (is_array($yamlDatas)) {
                if (true === $this->debug) {
                    $this->debug_data[$filename] = $yamlDatas;
                }

                if (self::CONFIG_FILE.'.'.self::EXTENSION === basename($filename) ||
                    self::CONFIG_FILE.'.'.$this->environment.'.'.self::EXTENSION === basename($filename)) {
                    foreach ($yamlDatas as $component => $config) {
                        if (!is_array($config)) {
                            $this->container->get('logger')->error('Bad configuration, array expected, given : '.$config);
                        }
                        $this->setSection($component, $config, $overwrite);
                    }
                } else {
                    $this->setSection(basename($filename, '.'.self::EXTENSION), $yamlDatas, $overwrite);
                }
            }
        } catch (ParseException $e) {
            throw new InvalidConfigException($e->getMessage(), null, $e, $e->getParsedFile(), $e->getParsedLine());
        }
    }
862541
public function append($append = [], $override = false)
    {
        $this->append = $override ? $append : array_merge($this->append, $append);

        return $this;
    }
1157104
private function exportToSingle(array $configurations, array $overrideData)
    {
        $configurations = array_replace_recursive($configurations, $overrideData);
        FileHelper::writeToFile($this->file, Data::toYaml($configurations));
        Schematic::info('Exported schema to '.$this->file);
    }
777955
private function importDefinitionsFromDirectory(array $overrideData)
    {
        if (!file_exists($this->path)) {
            throw new \Exception('Directory not found: ' . $this->path);
        }

        // Grab all yaml files in the schema directory.
        $schemaFiles = preg_grep('~\.(yml)$~', scandir($this->path));

        // Read contents of each file and add it to the definitions.
        foreach ($schemaFiles as $fileName) {
            $schemaStructure = explode('.', $this->fromSafeFileName($fileName));
            $dataTypeHandle = $schemaStructure[0];
            $recordName = $schemaStructure[1];

            $definition = Data::parseYamlFile($this->path . $fileName);

            // Check if there is data in the override file for the current record.
            if (isset($overrideData[$dataTypeHandle][$recordName])) {
                $definition = array_replace_recursive($definition, $overrideData[$dataTypeHandle][$recordName]);
            }

            $definitions[$dataTypeHandle][$recordName] = $definition;
        }

        return $definitions;
    }
86387
protected static function saveJson( $fileName, $data )
	{
		$json	= array();
		foreach( $data as $sectionName => $sectionData )
		{
			foreach( $sectionData as $pair )
			{
				$key	= $pair['key'];
				unset( $pair['key'] );
				$json[$sectionName][$key]	= $pair;
			}
		}
		$json	= ADT_JSON_Formater::format( $json, TRUE );
		return FS_File_Writer::save( $fileName, $json );
	}
682272
public function addArray($array, $override)
    {
        foreach ($array as $key => $value) {
            $this->add($key, $value, $override);
        }
    }
950373
public function send($override = false)
	{
		if ($this->sent && !$override)
		{
			throw new ResponseAlreadySentException('Response has already been sent');
		}

		// Call trigger
		$dispatcher = EventManager::dispatcher("onResponseSend");
		if( !$dispatcher->isRun() )
		{
			// fixed json
			$dispatcher->dispatch(new ResponseSendEvent($this));
		}

		// Send our response data
		$this->sendHeaders();
		$this->sendBody();

		// Lock the response from further modification
		$this->lock();

		// Mark as sent
		$this->sent = true;

		// If there running FPM, tell the process manager to finish the server request/response handling
		if (function_exists('fastcgi_finish_request'))
		{
			fastcgi_finish_request();
		}

		$dispatcher->complete();

		return $this;
	}
606811
public function add(array $translations, $override = false)
    {
        if ($override) {
            $this->_data = array_merge($this->_data, $translations);
        } else {
            $this->_data = array_merge($translations, $this->_data);
        }

        return true;
    }
409086
public function set($key, $value = null, $override = false)
    {
        // if key is array,
        // loop the set, while expecting value parameter to be override
        if(is_array($key))
        {
            $override = $value;

            foreach($key as $k => $val)
            {
                if($override === true)
                    $this->setOverride($k, $val);
                else
                    $this->data[$k] = $val;
            }

            return $this;
        }
        else
        {
            if($override === true)
                $this->setOverride($key, $value);
            else
                $this->data[$key] = $value;

            return $this;
        }
    }
655920
public function write(
        string $filename,
        string $data,
        int $mode = null,
        bool $ensureDirectory = false,
        bool $append = false
    ): bool {
        $mode = $mode ?? self::DEFAULT_FILE_MODE;

        try {
            if ($ensureDirectory) {
                $this->ensureDirectory(dirname($filename), $mode);
            }

            if ($this->exists($filename)) {
                //Forcing mode for existed file
                $this->setPermissions($filename, $mode);
            }

            $result = file_put_contents(
                $filename,
                $data,
                $append ? FILE_APPEND | LOCK_EX : LOCK_EX
            );

            if ($result !== false) {
                //Forcing mode after file creation
                $this->setPermissions($filename, $mode);
            }
        } catch (\Exception $e) {
            throw new WriteErrorException($e->getMessage(), $e->getCode(), $e);
        }

        return $result;
    }
766841
public static function log($data, $fileName = 'log', $ext='txt', $format='Ymd') {
        $filePath = Config::getx('path_temp') . 'logs'. DIRECTORY_SEPARATOR;
        if (!is_dir($filePath)) {
            if(!mkdir($filePath,0755,true)){
                throw new \Exception('Create log dir is fail!');
            }
        }
        $message = '[' . date("Y-m-d h:i:s") . ']  ';
        if($data instanceof \Throwable) {
            $message .= $data->getMessage().' in '.$data->getFile().':'.$data->getLine();
        }
        else {
            $message .= (is_array($data) ? print_r($data, true) : $data);
        }
        $message .="\n";
        $format = date($format);
        $fileName = "{$filePath}{$fileName}_{$format}.{$ext}";
        error_log($message, 3, $fileName);
    }
829539
public function syncWithTemplate($filePath, $overwrite = FALSE) {
    $sourcePath = $this->getBltRoot() . '/template/' . $filePath;
    $targetPath = $this->getRepoRoot() . '/' . $filePath;

    if ($this->getFileSystem()->exists($sourcePath)) {
      try {
        $this->getFileSystem()->copy($sourcePath, $targetPath, $overwrite);
      }
      catch (IOException $e) {
        throw $e;
      }
    }

  }