@@ -40,39 +40,43 @@ public function parse(string $content): PublicCode
4040 }
4141
4242 /**
43- * Parse publiccode.yml file
43+ * Parse a publiccode.yml file
4444 *
4545 * @param string $filePath Path to publiccode.yml
4646 * @return PublicCode
4747 * @throws ParserException
4848 * @throws ValidationException
4949 */
50- /* FIXME: re-enable */
51- /* public function parseFile(string $filePath): PublicCode */
52- /* { */
53- /* if (!file_exists($filePath)) { */
54- /* throw new ParserException("File not found: {$filePath}"); */
55- /* } */
56- /**/
57- /* $options = FFI::new('struct ParseOptions'); */
58- /* $options->DisableNetwork = $this->options->isDisableNetwork(); */
59- /**/
60- /* $result = $this->ffi->ParseFile($filePath, FFI::addr($options)); */
61- /**/
62- /* if ($result === null) { */
63- /* throw new ParserException('Failed to parse publiccode.yml file'); */
64- /* } */
65- /**/
66- /* return $this->processResult($result); */
67- /* } */
50+ public function parseFile (string $ filePath ): PublicCode
51+ {
52+ if (!file_exists ($ filePath )) {
53+ throw new ParserException ("File not found: {$ filePath }" );
54+ }
55+
56+ $ fp = @fopen ($ filePath , 'rb ' );
57+ if ($ fp === false ) {
58+ throw new ParserException ("Cannot open file: {$ filePath }" );
59+ }
60+
61+ try {
62+ $ content = stream_get_contents ($ fp );
63+ if ($ content === false ) {
64+ throw new ParserException ('Failed to read from stream ' );
65+ }
66+
67+ return $ this ->parse ($ content );
68+ } finally {
69+ fclose ($ fp );
70+ }
71+ }
6872
6973 /**
70- * Validate publiccode.yml file without parsing
74+ * Helper function to validate publiccode.yml file, with no error details
7175 *
7276 * @param string $filePath
7377 * @return bool
7478 */
75- public function validate (string $ filePath ): bool
79+ public function isValid (string $ filePath ): bool
7680 {
7781 try {
7882 $ this ->parseFile ($ filePath );
0 commit comments