/** * Decrypt a value * * ## Usage * * $driver->decrypt($string); * * @param string The encrypted value * @return string The decrypted value */ public function decrypt($string) { if (!Str::is($string = \base64_decode($string, true))) { throw new \Exception('Decryption error. Input value is not valid base64 data.'); } list($iv, $string) = array(Str::sub($string, 0, $this->iv_size()), Str::sub($string, $this->iv_size())); return \rtrim(\mcrypt_decrypt(static::$cipher, Crypt::key(), $string, static::$mode, $iv), ""); }
/** * Read all data from a datastore key * * @param string The datastore key * @return string Returns the contents of the datastore, otherwise null */ public function read($key) { if (!F::exists(self::$path . $key)) { return null; } // File based caches store have the expiration timestamp stored in // UNIX format prepended to their contents. This timestamp is then // extracted and removed when the cache is read to determine if the file // is still valid if (time() >= Str::sub($cache = F::get(self::$path . $key), 0, 10)) { $this->delete($key); return null; } return unserialize(substr($cache, 10)); }
/** * Provides the most *basic* form for a given model. This doesn't do much to figure * out what fields to use, and where to put them, but it does provide _very_ basic * scaffolding to get you up an running. * * [!!] In most instances you will wish to overload this method. * * @param \Nerd\Form Form instance to attach fields to, if null one is created * @return \Nerd\Form Form instance */ public function form(Form $form = null) { $form === null and $form = (new Form())->method('post'); $class = strtolower(Autoloader::denamespace(get_class($this))); $fieldset = $form->fieldset(); self::$columns->each(function ($column) use(&$form, &$fieldset, $class) { $type = 'text'; if ($column->is(Column::TYPE_DATE)) { $type = "datetime"; } elseif ($column->is(Column::TYPE_TEXT)) { $type = 'textarea'; } elseif ($column->is(Column::TYPE_TINYINT) and $column->constraint == 1) { $type = 'select'; } elseif ($column->is(Column::TYPE_NUMBER)) { $type = 'number'; } elseif ($column->is(Column::TYPE_ENUM)) { $type = 'select'; } if ($column->automatic) { $type = 'hidden'; } $field = $form->field($type, ['name' => "{$class}[{$column->field}]", 'id' => "{$class}_{$column->field}"], null); isset($this->_values[$column->field]) and $field->value($this->_values[$column->field]); if ($type === 'select') { if ($column->constraint == 1) { $field->options = [0 => 'false', 1 => 'true']; } else { $field->options = $column->options(); } if (isset($this->_values[$column->field])) { $field->selected = $this->_values[$column->field]; } } $field->label(Str::humanize($column->field)); if ($column->automatic) { $field->wrap(false)->wrapField(false); $field->label = null; } if ($type === 'text') { $field->maxlength($column->constraint); } if (!$column->nullable and !$type === 'datetime') { $field->required(true); } $fieldset->field($field); }); return $form; }