Saves data into a storage

@param array $data Data to be saved
@return void
359252
public function save(array $data)
    {
        // This is what we're going to store
        $seriaziledData = $this->serializer->serialize($data);
        $this->storageAdapter->set($this->key, $seriaziledData, $this->ttl);

        return true;
    }
912520
public function set_data( $data ) {

		foreach ( $this->child as $child ) {
			if ( method_exists( $child, 'set_data' ) ) {
				$child->set_data( $data );
			}
		}
		$this->data = $data;

	}
801392
protected function write(array $data)
    {
        $contents = $data ? json_encode($data) : '{}';

        $this->filesystem()->put($this->path, $contents);
    }
990439
public function unserialize($data)
    {
        $data = unserialize($data);

        if(is_array($data))
        {
            $data = array_reverse($data);

            foreach ($data as $item) {
                $this->push($item);
            }
        }
    }
1166919
public function persist($data = null)
    {
        if (is_null($data)) {
            $data = $this->database->toArray();
        }

        if (! is_array($data)) {
            $data = $data->toArray();
        }

        $this->makeDir($this->getFileName());

        file_put_contents($this->getFileName(), json_encode($data));
    }
130656
protected function _insert(array $data)
    {
        $data = $this->_setData($data);
        $sql = Sql::createSql($this->getAdapter())->insert($this->getTableName());
        $event = new Save([
            'action' => Save::INSERT,
            'data' => $data,
            'abort' => false
        ]);
        $this->getEventManager()->trigger(Save::BEFORE_SAVE, $this, $event);
        if ($event->abort) {
            return false;
        }
        $result = $sql->set($event->data)->execute();

        if ($result > 0) {
            $pmk = $this->getPrimaryKey();
            $this->$pmk = $this->getAdapter()->getLastInsertId();
            $this->getEventManager()->trigger(Save::AFTER_SAVE, $this, $event);
        }
        return $result > 0;
    }
858757
private function setData($data) {
        $this->indcheck = $data[0];
        $this->data = $data[1];
        $this->calculateChecksum();
        $this->data[] = $this->code[$this->checksumValue];
        $this->data[] = $this->code[self::KEY_STOP];
    }
57674
public function fill(array $data)
    {
        foreach ($data as $key => $value) {
            if (in_array($key, $this->fillable)) {
                $this->{$key} = $value;
            }
        }
    }
1352584
public function save($data)
	{
		if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
		{
			if ($data instanceof SimplePie)
			{
				$data = $data->data;
			}

			$data = serialize($data);
			return (bool) file_put_contents($this->name, $data);
		}
		return false;
	}
188568
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();
		$locationRepository = $main->getGeonamesEntityRepository();
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		$auth = $this->getServiceLocator()->get('ControllerPluginManager')->get('zfcUserAuthentication');
		$form = $this->getServiceLocator()->get('document.form.classifiedadd');
		
		$user = isset($data['user']) && is_array($data['user']) ? $data['user'] : null;
		$userId = null !== $user && isset($user['id']) ? $user['id'] : null;
		$email = isset($user['email']) ? $user['email'] : null;
		$name = isset($user['name']) ? $user['name'] : null;
		
		$document = isset($data['document']) && is_array($data['document']) ? $data['document'] : null;
		$documentId = null !== $document && isset($document['id']) ? $document['id'] : null;

		$children = isset($document["children"]) && is_array($document['children']) ? 
			$document["children"] : array();
		$metadata = isset($document['metadata']) && is_array($document['metadata']) ? 
			$document['metadata'] : array();
		
		$location = null;
		$locationUrl = isset($document["location"]) ? $document["location"] : null;
		
		if(null === $document) {
			throw new \Exception('Trying to save an empty document');
		}
		
		$data["document"]["documentType"] = Document::DOCUMENT_TYPE_CLASSIFIED;
		
		foreach($children as $k => $child) {
			if(!isset($child["content"])) {
				continue;
			}
			$image = $documentRepository->findByEncryptedId(
				$child["content"],
				'documentId'
			);
			unset($data["document"]["children"][$k]["content"]);
			$data["document"]["children"][$k]["documentId"] = $image->getDocumentId();
			$data["document"]["children"][$k]["documentType"] = Document::DOCUMENT_TYPE_IMAGE;
		}
		
		if(null !== $userId) {
			$repo = $main->getUserEntityRepository();
			$user = $repo->findByEncryptedId($userId, 'userId');
		} elseif(null !== $email) {
			$user = $userRepository->findOneBy(array('email' => $email));
			if(null === $user) {
				// @todo: validate email before insert
				$userService = $this->getServiceLocator()->get('user.service.user');
				
				// This was previously called $data and nothing worked, wonder why??
				$userdata = array();
				// This ws will take only CREATION of user, state will be always DEACTIVE
				$userdata['state'] = UserEntity::USER_STATE_DEACTIVE;
				// Edit these in the future for nicer localization and authorization
				$userdata['locale'] = 'it_IT';
				$userdata['role'] = 'guest';
				$userdata['email'] = $email;
				$userdata['name'] = $name;
				
				// This is necessary for validation
				$userdata['agreeterms'] = 1;
				$userdata['surname'] = $name;
					
				try {
					$user = $userService->save($userdata, false); // second arg for NOT to trigger event
				} catch(\Exception $e) {}
			}
		}
		
		$theUserId = $user instanceof UserEntity ? $user->getUserId() : null;
		$data["document"] = array_merge($data["document"], array('user' => $theUserId));
		
		$data["user"] = array(
			'name' => $name,
			'email' => $email
		);
		
		foreach($metadata as $meta) {
			if(isset($meta['key']) && 'comune' == $meta['key']) {
				$location = isset($meta['value']) && !empty($meta['value']) ? $meta['value'] : null;
				$location = $locationRepository->findOneBy(array('url' => $location));
				$data["document"]["geoname"] = $location ? $location->getGeonameId() : '';
				break;
			}
		}
		
		if (isset($document["location"]) && null === $location && null !== $locationUrl) {
			$location = $locationRepository->findOneBy(array('url' => $locationUrl));
			$data["document"]["geoname"] = $location instanceof GeonamesEntity
				? $location->getGeonameId() : '';
		}
		
		// @todo: get from a service
		if(null === $documentId) {
			$entity = new Document();
		} else {
			$repo = $main->getDocumentEntityRepository();
			$entity = $repo->findByEncryptedId($documentId, 'documentId');
		}
    	
		if(null === $documentId) {
			$data["document"]["state"] = $auth->hasIdentity() ? 
				Document::DOCUMENT_STATE_ACTIVE : Document::DOCUMENT_STATE_DEACTIVE;
		} else {
			$data["document"]["state"] = $entity->getState();
		}
		
		// checking for permission, only if we are in edit mode
		if(!$this->checkIfOwnerOrAdmin($entity) && null !== $documentId) {
			throw new \Exception('Non possiedi i permessi per agire su questo documento');
		}
		
		$form->setData($data);
		$form->bind($entity);
		
		if (!$form->isValid()) {
			throw new \Exception(serialize($form->getMessages()));
		}
		
		$em->persist($entity);
		$em->flush();
		$key = $documentRepository->getEncryptedId($entity->getDocumentId());
		if($cache->hasItem($key)) {
			$cache->removeItem($key);
		}
		
		// Depending on existence of $documentId will be dispatched the correct event
		if($documentId) {
		    
		} else {
		    $url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
		    $classifiedModel = $this->getServiceLocator()->get('document.model.classifiedAdminListing');
		    $classifiedModel->init($entity, $this->getServiceLocator());
		    $event = new ClassifiedCreatedEvent(__FUNCTION__, null, array(
    		    'to' => $classifiedModel->email, 
    		    'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
    		    'fullname' => $classifiedModel->fullname,
		        'title' => $classifiedModel->title, 
		        'hash' => $classifiedModel->hashId,
		        'state' => $classifiedModel->state
    		));
		    $this->getEventManager()->trigger('classifiedCreated.post', $this, $event);
		}
		
		return $entity;
    }
1239611
private function saveCache(array $data)
    {
        $this->cache = $data; // Save new data in object to avoid useless I/O access
        $opt = '';
        if (ForumEnv::get('FEATHER_DEBUG')) {
            $opt = JSON_PRETTY_PRINT;
        }
        return file_put_contents($this->getCacheFile(), json_encode($data, $opt));
    }
1340394
public function save($data = [])
    {
        if (!$data || count($data) == 0) {
            $data = $_POST;
        }
        $data += [
            'qsID' => null,
            'oldQsID' => null,
            'questions' => [],
        ];

        $b = $this->getBlockObject();
        $c = $b->getBlockCollectionObject();

        $db = Database::connection();
        if (intval($this->bID) > 0) {
            $q = "select count(*) as total from {$this->btTable} where bID = " . intval($this->bID);
            $total = $db->getOne($q);
        } else {
            $total = 0;
        }

        if (isset($_POST['qsID']) && $_POST['qsID']) {
            $data['qsID'] = $_POST['qsID'];
        }
        if (!$data['qsID']) {
            $data['qsID'] = time();
        }

        if (isset($data['questionSetId'])) {
            // This is specifically set when using the migration tool
            $data['qsID'] = $data['questionSetId'];
        }

        if (!$data['oldQsID']) {
            $data['oldQsID'] = $data['qsID'];
        }
        $data['bID'] = intval($this->bID);

        if (!empty($data['redirectCID'])) {
            $data['redirect'] = 1;
        } else {
            $data['redirect'] = 0;
            $data['redirectCID'] = 0;
        }

        if (empty($data['addFilesToSet'])) {
            $data['addFilesToSet'] = 0;
        }

        if (!isset($data['surveyName'])) {
            $data['surveyName'] = '';
        }

        if (!isset($data['submitText'])) {
            $data['submitText'] = '';
        }

        if (!isset($data['notifyMeOnSubmission'])) {
            $data['notifyMeOnSubmission'] = 0;
        }

        if (!isset($data['thankyouMsg'])) {
            $data['thankyouMsg'] = '';
        }

        if (!isset($data['displayCaptcha'])) {
            $data['displayCaptcha'] = 0;
        }

        $v = [$data['qsID'], $data['surveyName'], $data['submitText'], intval($data['notifyMeOnSubmission']), $data['recipientEmail'], $data['thankyouMsg'], intval($data['displayCaptcha']), intval($data['redirectCID']), intval($data['addFilesToSet']), intval($this->bID)];

        //is it new?
        if (intval($total) == 0) {
            $q = "insert into {$this->btTable} (questionSetId, surveyName, submitText, notifyMeOnSubmission, recipientEmail, thankyouMsg, displayCaptcha, redirectCID, addFilesToSet, bID) values (?, ?, ?, ?, ?, ?, ?, ?, ?,?)";
        } else {
            $v[] = $data['qsID'];
            $q = "update {$this->btTable} set questionSetId = ?, surveyName=?, submitText=?, notifyMeOnSubmission=?, recipientEmail=?, thankyouMsg=?, displayCaptcha=?, redirectCID=?, addFilesToSet=? where bID = ? AND questionSetId= ?";
        }

        $rs = $db->query($q, $v);

        //Add Questions (for programmatically creating forms, such as during the site install)
        if (count($data['questions']) > 0) {
            $miniSurvey = new MiniSurvey();
            foreach ($data['questions'] as $questionData) {
                $miniSurvey->addEditQuestion($questionData, 0);
            }
        }

        $this->questionVersioning($data);

        return true;
    }
787282
public function setFromArray(array $data): void
    {
        foreach ($data as $key => $value) {
            $this->container[$key] = $value;
        }
    }
233030
public function set(array $data)
    {
        $this->data = [];
        $this->replace = false;

        foreach ($data as $key => $value) {
            $this->add($key, $value);
        }
    }
136161
public function save($data): void
    {
        if (\is_string($data)) {
            // Make sure that the string is valid data.
            try {
                $this->formatter->decode($data);
            } catch (RuntimeException $e) {
                throw new RuntimeException(sprintf("Failed to save file '%s': %s", $this->getFilePath(), $e->getMessage()), $e->getCode(), $e);
            }
            $encoded = $data;
        } else {
            $encoded = $this->formatter->encode($data);
        }

        parent::save($encoded);
    }
317373
public function save($id, array $data)
    {
        if(!empty($id) && (is_string($id) || is_numeric($id))) {
            $this->setFile($id);
            if ($this->file) {
                if (file_exists($this->file)) {
                    $this->update($id, $data);
                } else {
                    $this->add($id, $data);
                }
            }
        }
    }
911039
public function setData($data = [])
    {
        if (!is_array($data) && is_string($data)) {
            $data = parse_str($data);
        }
        if (count($data) == 0) {
            $this->data = [];
        } else {
            $this->data = $data;
        }
        $this->debug->debug(__FUNCTION__, 'Data into Request: ', $this->data);
    }