Skip to content
Newer
Older
100644 73 lines (45 sloc) 1.82 KB
6d27a29 @divoxx Rename RubyPhpSerialization to PhpSerialization
authored Oct 2, 2009
1 = PhpSerialization
f5dd4fd @divoxx Initial commit to ruby_php_serialization.
authored Sep 25, 2009
2
ef5fb97 @divoxx Fix some names and documentations
authored Sep 25, 2009
3 Ruby implementation of PHP's serialization. This is special useful for reading PHP session files.
4
af94db2 @divoxx Add serialization examples to README
authored Oct 5, 2009
5 == Serialization examples
6
7 Primitive values
8
9 PhpSerialization.dump(10) # => "i:10;"
10 PhpSerialization.dump("Name") # => "s:4:\"Name\";"
11 PhpSerialization.dump(true) # => "b:1;"
12 PhpSerialization.dump(nil) # => "N;"
13
14 Array
15
d3541dc @divoxx Fix README
authored Oct 6, 2009
16 PhpSerialization.dump([true, "foo"]) # => "a:2:{i:0;b:1;i:1;s:3:\"foo\";}"
af94db2 @divoxx Add serialization examples to README
authored Oct 5, 2009
17
18 Hash
19
d3541dc @divoxx Fix README
authored Oct 6, 2009
20 PhpSerialization.dump("name" => "Rodrigo", "age" => 23) # => "a:2:{s:4:\"name\";s:7:\"Rodrigo\";s:3:\"age\";i:23;}"
af94db2 @divoxx Add serialization examples to README
authored Oct 5, 2009
21
22 Object
23
24 class Person
25 attr_accessor :name, :age
26 end
27
28 person = Person.new
29 person.name = "Rodrigo"
30 person.age = 23
31
d3541dc @divoxx Fix README
authored Oct 6, 2009
32 PhpSerialization.dump(person) # => "O:6:\"Person\":2:{s:4:\"name\";s:7:\"Rodrigo\";s:3:\"age\";i:23;}"
af94db2 @divoxx Add serialization examples to README
authored Oct 5, 2009
33
e1c7b56 @divoxx Add object unserialization to Struct and documentation
authored Sep 25, 2009
34 == Unserialization examples
f5dd4fd @divoxx Initial commit to ruby_php_serialization.
authored Sep 25, 2009
35
e1c7b56 @divoxx Add object unserialization to Struct and documentation
authored Sep 25, 2009
36 Primitive values
37
84c3ad5 @divoxx Rename Parser to Unserializer and name the method "load" instead of "…
authored Oct 2, 2009
38 PhpSerialization.load('i:10;') # => 10
39 PhpSerialization.load('s:4:"Name";') # => "Name"
40 PhpSerialization.load('b:1;') # => true
41 PhpSerialization.load('N;') # => nil
66d1d1d @divoxx Remove tabs from README
authored Sep 25, 2009
42
e1c7b56 @divoxx Add object unserialization to Struct and documentation
authored Sep 25, 2009
43 Array
44
d3541dc @divoxx Fix README
authored Oct 6, 2009
45 PhpSerialization.load('a:2:{i:0;b:1;i:1;s:3:"foo";}') # => [true, "foo"]
66d1d1d @divoxx Remove tabs from README
authored Sep 25, 2009
46
e1c7b56 @divoxx Add object unserialization to Struct and documentation
authored Sep 25, 2009
47 Hash
48
d3541dc @divoxx Fix README
authored Oct 6, 2009
49 PhpSerialization.load('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}') # => {"name" => "Rodrigo", "age" => 23}
66d1d1d @divoxx Remove tabs from README
authored Sep 25, 2009
50
e1c7b56 @divoxx Add object unserialization to Struct and documentation
authored Sep 25, 2009
51 Object
52
66d1d1d @divoxx Remove tabs from README
authored Sep 25, 2009
53 class Person
54 attr_accessor :name, :age
55 end
56
d3541dc @divoxx Fix README
authored Oct 6, 2009
57 person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
66d1d1d @divoxx Remove tabs from README
authored Sep 25, 2009
58 person.name # => "Rodrigo"
59 person.age # => 23
60
e1c7b56 @divoxx Add object unserialization to Struct and documentation
authored Sep 25, 2009
61 Object without class will map to a Struct
62
d3541dc @divoxx Fix README
authored Oct 6, 2009
63 person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
66d1d1d @divoxx Remove tabs from README
authored Sep 25, 2009
64 person.class # => Struct::Person
65 person.name # => "Rodrigo"
66 person.age # => 23
84c3ad5 @divoxx Rename Parser to Unserializer and name the method "load" instead of "…
authored Oct 2, 2009
67
68 You can also call unserialize() or restore(), they are alias to the load().
f5dd4fd @divoxx Initial commit to ruby_php_serialization.
authored Sep 25, 2009
69
70 == Copyright
71
72 Copyright (c) 2009 Rodrigo Kochenburger. See LICENSE for details.
Something went wrong with that request. Please try again.