Stores given data into a file

@param  object $data IDS_Report

@throws Exception if the logfile isn't writeable
@return boolean
13123
public function execute(IDS_Report $data) 
    {

        /*
         * In case the data has been modified before it might  be necessary 
         * to convert it to string since we can't store array or object 
         * into a file
         */
        $data = $this->prepareData($data);

        if (is_string($data)) {

            if (file_exists($this->logfile)) {
                $data = trim($data);

                if (!empty($data)) {
                    if (is_writable($this->logfile)) {

                        $handle = fopen($this->logfile, 'a');
                        fwrite($handle, trim($data) . "\n");
                        fclose($handle);

                    } else {
                        throw new Exception(
                            'Please make sure that ' . $this->logfile . 
                                ' is writeable.'
                        );
                    }
                }
            } else {
                throw new Exception(
                    'Given file does not exist. Please make sure the
                    logfile is present in the given directory.'
                );
            }
        } else {
            throw new Exception(
                'Please make sure that data returned by
                IDS_Log_File::prepareData() is a string.'
            );
        }

        return true;
    }
1169963
public function write($data)
    {
        if (!$this->connected && !$this->connect()) {
            return false;
        }
        $totalBytes = strlen($data);
        $written = 0;
        while ($written < $totalBytes) {
            $rv = fwrite($this->connection, substr($data, $written));
            if ($rv === false || $rv === 0) {
                return $written;
            }
            $written += $rv;
        }

        return $written;
    }
1337682
public function withFileData($data)
    {
        $stream = new Stream('php://temp', Stream::MODE_READ_WRITE_RESET);

        $stream->write($data);
        $stream->rewind();

        return $this->withFileStream($stream);
    }
1054274
private function log($data)
    {
        $data = date(DATE_RSS, time()) . "\t$data\n";
        file_put_contents($this->storage('.log'), $data, FILE_APPEND);
    }
912947
public function execute(IDS_Report $data)
    {

        if ($this->safemode) {
            if ($this->isSpamAttempt()) {
                return false;
            }
        }

        /*
        * In case the data has been modified before it might
        * be necessary to convert it to string since it's pretty
        * senseless to send array or object via e-mail
        */
        $data = $this->prepareData($data);

        if (is_string($data)) {
            $data = trim($data);

            // if headers are passed as array, we need to make a string of it
            if (is_array($this->headers)) {
                $headers = "";
                foreach ($this->headers as $header) {
                    $headers .= $header . "\r\n";
                }
            } else {
                $headers = $this->headers;
            }

            if (!empty($this->recipients)) {
                if (is_array($this->recipients)) {
                    foreach ($this->recipients as $address) {
                        $this->send(
                            $address,
                            $data,
                            $headers,
                            $this->envelope
                        );
                    }
                } else {
                    $this->send(
                        $this->recipients,
                        $data,
                        $headers,
                        $this->envelope
                    );
                }
            }

        } else {
            throw new Exception(
                'Please make sure that data returned by
                 IDS_Log_Email::prepareData() is a string.'
            );
        }

        return true;
    }
421888
public function put($data)
    {
        if (empty($data) or !is_array($data))
        {
            return false;
        }
        if ($this->db->insert($data, $this->table))
        {
            $lastInsertId = $this->db->lastInsertId();
            if ($lastInsertId == 0)
            {
                return true;
            }
            else
            {
                return $lastInsertId;
            }
        }
        else
        {
            return false;
        }
    }
1260971
public function addStreamData($data) {
        if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
            return FALSE;
        }

        $length = fwrite($this->streamData, $data, strlen($data));
        if ($length != strlen($data)) {
            throw new Exception("File IO: Error writing; Length mismatch: Expected " . strlen($data) . " bytes, wrote " . ($length === FALSE ? "NONE!" : $length));
        }
        $this->streamFileLength += $length;

        return $length;
    }
934979
public function save($data = null) {
		if (!parent::save()) {
			return false;
		}

		if ($data) {
			// new image
			$this->simpletype = 'image';
			$this->saveImageFile($data);
			$this->saveThumbnails();
			$this->extractExifData();
		}

		return true;
	}
945789
public function dump($file, array $data)
    {
        $dir = dirname($file);

        if (!is_dir($dir)) {
            mkdir($dir, 0755, true);
        }

        $fileInfo = new SplFileInfo($file);

        if ($fileInfo->isFile()) {
            if ($fileInfo->isWritable()) {
                $fileObject = $fileInfo->openFile('w');
            } else {
                throw new Exception(sprintf('File "%s" is not writable.', $file));
            }
        } else {
            $fileObject = $fileInfo->openFile('w');
        }

        if (null !== $fileObject->fwrite('<?php return ' . var_export($data, true) . ';')) {
            return true;
        }

        return false;
    }
1335220
public function write($data)
    {
        if (!$this->connected) {
            if (!$this->connect()) {
                return false;
            }
        }
        return fwrite($this->connection, $data, strlen($data));
    }
1052283
public static function log(...$data)
    {
        $filename = static::options('root') . '/storage/log/access';
        if (is_array($data) && count($data) === 1) {
            $data = $data[0];
        }
        return File::write($filename, $data, true);
    }
911275
public function write($data, $lock = false) {
        if (!is_string($data) && !is_integer($data)) {
            $data = var_export($data, true);
        }
        if (is_bool($lock)) {
            $lock = $lock ? LOCK_EX : 0;
        }
        return file_put_contents($this->fullName, $data, $lock);
    }
417725
public function saveCategory($data = [])
    {
        if (!empty($data)) {
            $this->data($data);
        }
        $validate = new \gmars\rbac\validate\PermissionCategory();
        if (!$validate->check($this)) {
            throw new Exception($validate->getError());
        }
        $data = $this->getData();
        if (isset($data['id']) && !empty($data['id'])) {
            $this->isUpdate(true);
        }
        $this->save();
        return $this;
    }
532245
public function write($id, $data)
    {
        try {
            return $this->db->write($id, $data);
        } catch (\Exception $e) {
            throw $e;
        }
    }
982982
public function save($data)
    {
        $argv = compact('data');
        $argv = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_PRE_SAVE, $this, $argv);

        $data = $argv['data'];

        if ($data instanceof ModelInterface) {
            $data = $this->getHydrator()->extract($data);
        }

        $pk = $this->getMapper()->getPrimaryKey();
        $id = $data[$pk];
        unset($data[$pk]);

        if (0 === $id || null === $id || '' === $id) {
            $result = $this->getMapper()->insert($data);
            $this->clearCacheTags();
        } else {
            if ($this->getById($id)) {
                $result = $this->getMapper()->update($data, [$pk => $id]);
            } else {
                throw new ServiceException('ID ' . $id . ' does not exist');
            }

            $this->removeCacheItem($id);
        }

        $argv = compact('data', 'result');
        $argv = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_POST_SAVE, $this, $argv);

        return $result;
    }
1103709
public function save(array $data)
    {
		// All the services we need
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		$documentRepository = $main->getDocumentEntityRepository();
		$userRepository = $main->getUserEntityRepository();
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		$form = $this->getServiceLocator()->get('document.form.classifiedimageadd');
    	
		$classifiedId = !empty($data['classifiedid']) ? $data['classifiedid'] : null;
	    $classified = null !== $classifiedId ? 
	        $documentRepository->findByEncryptedId($classifiedId, 'documentId') : null;
	    
	    // remove parent cache
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		if (!empty($classifiedId) && $cache->hasItem($classifiedId)) {
			$cache->removeItem($classifiedId);
		}
	    
		$userId = !empty($data['userid']) ? $data['userid'] : null;
	    $user = null !== $userId ? 
	        $userRepository->findByEncryptedId($userId, 'userId') : null;
		
		$entity = new Document();
		$form->setData($data);
		
		if (!$form->isValid()) {
			throw new \Exception(serialize($form->getMessages('files')));
		}
		
		$data = $form->getData();
			
		// @todo Better recover this in a smarter way
		$files = isset($data['files']) ? $data['files'] : array();
		$firstFile = reset($files);
		
		if(empty($firstFile)) {
			throw new \Exception(serialize(array('Empty file')));
		}
		
		$title = is_array($firstFile) && isset($firstFile['name']) ? 
			$firstFile['name'] : '';
			
		$entity->setDocumentType(Document::DOCUMENT_TYPE_IMAGE);
		$entity->setTitle($title);
		$entity->setParent($classified);
		$entity->setUser($user);
		$entity->setState(Document::DOCUMENT_STATE_ACTIVE);
		
		$em->persist($entity);
		$em->flush();
		
    	// trigger saveClassified event with the saved entity
    	$this->getEventManager()->trigger('imageSaved', null, $entity);
    	
    	return $entity;
    }
565529
public function stream_write($data)
    {
        if ($this->_upload === null) {
            return false;
        }
        $this->_upload->addContent($data);
        $result = StringHelper::byteLength($data);
        $this->_pointerOffset += $result;
        return $result;
    }