Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit c62f8d4

Browse files
committed
Fix dependency on namespace fallback in dorm codegen
1 parent a4c8682 commit c62f8d4

File tree

7 files changed

+69
-48
lines changed

7 files changed

+69
-48
lines changed

.travis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if !(hhvm --version | grep -q -- -dev); then
2121
vendor/bin/hhast-lint
2222
fi
2323

24-
hhvm examples/dorm/codegen.php examples/dorm/demo/DormUserSchema.php
24+
hhvm examples/dorm/codegen.hack examples/dorm/demo/DormUserSchema.php
2525
if ! git diff --exit-code examples/; then
2626
echo "Demo codegen not up to date."
2727
exit 1

examples/dorm/CodegenDorm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function generate(): void {
6060
$path = $rc->getFileName() as string;
6161
$pos = \strrpos((string) $path, '/');
6262
$dir = \substr($path, 0, $pos + 1);
63-
$gen_from = 'codegen.php '.$this->getSchemaName().'Schema';
63+
$gen_from = 'codegen.hack '.$this->getSchemaName().'Schema';
6464

6565
// This generates a file (we pass the file name) that contains the
6666
// class defined above and saves it.

examples/dorm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ DORM stands for Demo ORM, and although it actually works, it is not indendeed fo
1010
1. ** Optional ** If you want to try running the generated code (as opposed to just generating the code), you'll need to set up the database:
1111
1. Using your favorite database, create the "user" table with the schema shown in demo_usage.php
1212
2. In file DemoUserSchema.php, change the getDsn method to return the DSN pointing to your database.
13-
2. To generate the code, run: php codegen.php demo/DormUserSchema.php. This will generate the files DormUser.php and DormUserMutator.php. Take a look a the generated code!
13+
2. To generate the code, run: `codegen.hack demo/DormUserSchema.php`. This will generate the files DormUser.php and DormUserMutator.php. Take a look a the generated code!
1414
3. If you followed step 1, run php demo/demo_usage.php to have it inserting a rown in the database.
1515

1616
Here are a few things that you can try out to better understand the code generation:

examples/dorm/codegen.hack

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env hhvm
2+
/*
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
* All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*
9+
*/
10+
11+
namespace Facebook\HackCodegen;
12+
13+
use namespace HH\Lib\{C, Vec};
14+
15+
require_once(__DIR__.'/../../vendor/hh_autoload.hh');
16+
17+
final class DormCodegenCLI extends \Facebook\CLILib\CLIWithRequiredArguments {
18+
<<__Override>>
19+
public static function getHelpTextForRequiredArguments(): vec<string> {
20+
return vec['FILENAME'];
21+
}
22+
23+
<<__Override>>
24+
protected function getSupportedOptions(
25+
): vec<\Facebook\CLILib\CLIOptions\CLIOption> {
26+
return vec[];
27+
}
28+
29+
<<__Override>>
30+
public async function mainAsync(): Awaitable<int> {
31+
$fname = C\firstx($this->getArguments());
32+
if (!\file_exists($fname)) {
33+
await $this->getStderr()
34+
->writeAsync(" File doesn't exist: ".$fname."\n\n");
35+
return 1;
36+
}
37+
38+
$classes = \get_declared_classes();
39+
require_once($fname);
40+
$new_classes = Vec\diff(\get_declared_classes(), $classes);
41+
42+
43+
foreach ($new_classes as $class_name) {
44+
$ref = new \ReflectionClass($class_name);
45+
if ($ref->isAbstract()) {
46+
continue;
47+
}
48+
$instance = $ref->newInstance() as DormSchema;
49+
await $this->getStdout()
50+
->writeAsync("Generating code for ".$class_name."\n");
51+
(new CodegenDorm($instance))->generate();
52+
(new CodegenMutator($instance))->generate();
53+
}
54+
55+
return 0;
56+
}
57+
}
58+
59+
<<__EntryPoint>>
60+
async function dorm_codegen_cli_main(): Awaitable<noreturn> {
61+
$exit_code = await DormCodegenCLI::runAsync();
62+
exit($exit_code);
63+
}

examples/dorm/codegen.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

examples/dorm/demo/DormUser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
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 codegen.php DormUserSchema
6+
* To re-generate this file run codegen.hack DormUserSchema
77
*
88
*
9-
* @partially-generated SignedSource<<9e4466dec9ad5e268b1df61c65b84fd3>>
9+
* @partially-generated SignedSource<<bb328713820ebe866a4e0292daa0a4de>>
1010
*/
1111
use namespace Facebook\TypeAssert;
1212

examples/dorm/demo/demo_usage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* );
3131
*
3232
* Before trying this example, you'll need to generate the code by running
33-
* php codegen.php demo/DormUserSchema.php.
33+
* php codegen.hack demo/DormUserSchema.php.
3434
*/
3535
$id = DormUserMutator::create()
3636
->setFirstName('John')

0 commit comments

Comments
 (0)