Skip to content

Commit 6a9bc82

Browse files
Merge pull request #4 from facebook/namespace
Namespace
2 parents 37e2395 + 77edb77 commit 6a9bc82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+194
-65
lines changed

examples/dorm/CodegenDorm.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11+
namespace Facebook\HackCodegen;
12+
1113
/**
1214
* For a given DormSchema, this class generates code for a class
1315
* that will allow to read the data from a database and store it
@@ -20,7 +22,8 @@ public function __construct(
2022
) {}
2123

2224
private function getSchemaName(): string {
23-
$name = get_class($this->schema);
25+
$ref = new \ReflectionClass($this->schema);
26+
$name = $ref->getShortName();
2427
return Str::endsWith($name, 'Schema')
2528
? Str::substr($name, 0, -6)
2629
: $name;
@@ -38,7 +41,7 @@ public function generate(): void {
3841
->addMethod($this->getLoad())
3942
->addMethods($this->getGetters());
4043

41-
$rc = new ReflectionClass(get_class($this->schema));
44+
$rc = new \ReflectionClass(get_class($this->schema));
4245
$path = $rc->getFileName();
4346
$pos = strrpos($path, '/');
4447
$dir = substr($path, 0, $pos + 1);

examples/dorm/CodegenMutator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11+
namespace Facebook\HackCodegen;
12+
1113
/**
1214
* For a given DormSchema, this class generates code for a class
1315
* that will allow to insert rows in a database.
@@ -19,7 +21,8 @@ public function __construct(
1921
) {}
2022

2123
private function getName(): string {
22-
$name = get_class($this->schema);
24+
$ref = new \ReflectionClass($this->schema);
25+
$name = $ref->getShortName();
2326
$remove_schema = Str::endsWith($name, 'Schema')
2427
? Str::substr($name, 0, -6)
2528
: $name;
@@ -44,7 +47,7 @@ public function generate(): void {
4447
->addMethod($this->getCheckRequiredFieldsMethod())
4548
->addMethods($this->getSetters());
4649

47-
$rc = new ReflectionClass(get_class($this->schema));
50+
$rc = new \ReflectionClass(get_class($this->schema));
4851
$path = $rc->getFileName();
4952
$pos = strrpos($path, '/');
5053
$dir = substr($path, 0, $pos + 1);

examples/dorm/codegen.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11+
namespace Facebook\HackCodegen;
12+
1113
require_once('vendor/autoload.php');
1214
require_once('core/DormSchema.php');
1315
require_once('core/DormField.php');
@@ -30,7 +32,7 @@
3032

3133

3234
foreach($new_classes as $class_name) {
33-
$ref = new ReflectionClass($class_name);
35+
$ref = new \ReflectionClass($class_name);
3436
if ($ref->isAbstract()) {
3537
continue;
3638
}

examples/dorm/core/DormField.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11+
namespace Facebook\HackCodegen;
12+
1113
class DormField {
1214
private bool $optional = false;
1315
private bool $manual = false;

examples/dorm/core/DormSchema.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11+
namespace Facebook\HackCodegen;
12+
1113
interface DormSchema {
1214
public function getFields(): Map<string, DormField>;
1315
public function getDsn(): string;

examples/dorm/demo/DormUser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* This file is partially generated. Only make modifications between BEGIN
44
* MANUAL SECTION and END MANUAL SECTION designators.
55
*
6-
* To re-generate this file run /home/amarcu/codegen/examples/dorm/codegen.php
6+
* To re-generate this file run
7+
* /home/ubuntu/hack-codegen/examples/dorm/codegen.php
78
*
89
*
9-
* @partially-generated SignedSource<<83bf890797c14d6a2809c949981e1f41>>
10+
* @partially-generated SignedSource<<f9e8b0c880da41854d491905f3a7314e>>
1011
*/
1112

1213
final class DormUser {

examples/dorm/demo/DormUserMutator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* This file is partially generated. Only make modifications between BEGIN
44
* MANUAL SECTION and END MANUAL SECTION designators.
55
*
6-
* To re-generate this file run /home/amarcu/codegen/examples/dorm/codegen.php
6+
* To re-generate this file run
7+
* /home/ubuntu/hack-codegen/examples/dorm/codegen.php
78
*
89
*
9-
* @partially-generated SignedSource<<7b060a2196463538ccc10378f0058076>>
10+
* @partially-generated SignedSource<<f9c5059806c0ec22c4ba40846c277eb9>>
1011
*/
1112

1213
final class DormUserMutator {

examples/dorm/demo/DormUserSchema.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11+
namespace Facebook\HackCodegen;
12+
1113
class DormUserSchema implements DormSchema {
1214
public function getFields(): Map<string, DormField> {
1315
return Map {

examples/dorm/demo/demo_usage.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11+
namespace Facebook\HackCodegen;
12+
1113
require_once('DormUserMutator.php');
1214
require_once('DormUser.php');
1315

@@ -33,7 +35,7 @@
3335
$id = DormUserMutator::create()
3436
->setFirstName('John')
3537
->setLastName('Smith')
36-
->setBirthday(new DateTime('1978-03-26'))
38+
->setBirthday(new \DateTime('1978-03-26'))
3739
->setCountryId(54)
3840
->setIsActive(true)
3941
->save();

lib/Filesystem.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11+
namespace Facebook\HackCodegen;
12+
1113
final class Filesystem {
1214
public static function createTemporaryFile(
1315
string $prefix = '',
@@ -25,14 +27,14 @@ public static function remove(string $path): void {
2527
return;
2628
}
2729
if (!unlink($path)) {
28-
throw new Exception("Unable to remove `{$path}'.");
30+
throw new \Exception("Unable to remove `{$path}'.");
2931
}
3032
}
3133

3234
public static function readFile(string $path): string {
3335
$data = @file_get_contents($path);
3436
if ($data === false) {
35-
throw new Exception("Failed to read file `{$path}'.");
37+
throw new \Exception("Failed to read file `{$path}'.");
3638
}
3739

3840
return $data;
@@ -42,7 +44,7 @@ public static function writeFile(string $path, string $data): void {
4244
$res = @file_put_contents($path, $data);
4345

4446
if ($res === false) {
45-
throw new Exception("Failed to write file `{$path}'.");
47+
throw new \Exception("Failed to write file `{$path}'.");
4648
}
4749
}
4850

0 commit comments

Comments
 (0)