Skip to content

Commit 9b469ca

Browse files
committed
Add demo for different endpoints, add FONT_* constants for Post styles
1 parent 5219e8a commit 9b469ca

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

example/differentEndpoint.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace writeas;
5+
6+
require_once( "../lib/writeas.php" );
7+
8+
$context = new \writeas\Context( "https://localhost:8080/api" );
9+
$post = new Post( $context );
10+
$post->body = "Hello from Writeas.php";
11+
$post->save();
12+
13+
?>

lib/Collection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@ function __construct( Context $context ) {
1818
$this->context = $context;
1919
}
2020

21+
public function get( string $alias ) {
22+
$url = "/collections/" . $alias;
23+
$response = $this->context->request( $url );
24+
$this->context->updateObject( $this, $response );
25+
var_dump($this);
26+
}
27+
2128
}
2229
?>

lib/Context.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public function request( string $url, ?string $postdata = null ) {
3232

3333
curl_close( $this->ch );
3434

35-
if ( $output !== false ) {
35+
if ( $output !== false && !empty( $output ) ) {
3636
$js = @json_decode( $output );
3737
if ( !empty( $js ) ) {
3838
return $js;
3939
}
4040

41-
throw new Exception( "Failed to decode response" );
41+
throw new \Exception( "Failed to decode response" );
4242
}
4343

4444
return null;

lib/Styles.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace writeas;
5+
6+
// Font styles
7+
// Serif is default and the same as norm
8+
const FONT_SANS = "sans";
9+
const FONT_SERIF = "serif";
10+
const FONT_NORM = "norm";
11+
const FONT_WRAP = "wrap";
12+
const FONT_MONO = "mono";
13+
const FONT_CODE = "code";
14+
?>

lib/writeas.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
require_once( "Context.php" );
88
require_once( "Post.php" );
99
require_once( "Collection.php" );
10+
require_once( "Styles.php" );
1011
?>

0 commit comments

Comments
 (0)