code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function model($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->generate_model($plugin, $name);
}
|
Generate model for plugin
wpmvc generate model <plugin> <model>
@param mixed $args
|
model
|
php
|
tombenner/wp-mvc
|
core/shells/generate_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/generate_shell.php
|
MIT
|
public function scaffold($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->generate_controllers($plugin, $name);
$this->generate_model($plugin, $name);
$this->generate_views($plugin, $name);
}
|
Generate models, views, and controllers for an entity
wpmvc generate scaffold <plugin> <model>
@param mixed $args
|
scaffold
|
php
|
tombenner/wp-mvc
|
core/shells/generate_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/generate_shell.php
|
MIT
|
public function views($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->generate_views($plugin, $name);
}
|
Generate all views for CRUD operations for model
wpmvc generate views <plugin> <model>
@param mixed $args
|
views
|
php
|
tombenner/wp-mvc
|
core/shells/generate_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/generate_shell.php
|
MIT
|
public function widget($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->generate_widget($plugin, $name);
}
|
Generate a basic wordpress widget
wpmvc generate widget <plugin> <name>
@param array $args
|
widget
|
php
|
tombenner/wp-mvc
|
core/shells/generate_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/generate_shell.php
|
MIT
|
private function generate_widget($plugin, $name) {
$plugin_app_path = $this->get_plugin_app_path($plugin);
$title = MvcInflector::titleize($name);
$file_name = MvcInflector::underscore($name);
$class_name = MvcInflector::camelize($plugin).'_'.MvcInflector::camelize($name);
$name_underscore = MvcInflector::underscore($class_name);
$vars = array(
'name' => $name,
'title' => $title,
'name_underscore' => $name_underscore,
'class_name' => $class_name
);
$target_path = $plugin_app_path.'widgets/'.$file_name.'.php';
$this->templater->create('widget', $target_path, $vars);
}
|
Generate a basic wordpress widget
@param string $plugin plugin where widget will reside
@param string $name name of widget
|
generate_widget
|
php
|
tombenner/wp-mvc
|
core/shells/generate_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/generate_shell.php
|
MIT
|
public function main($args) {
$shells = $this->get_available_shells();
$this->out('Available Shells:');
$table = new Console_Table(
CONSOLE_TABLE_ALIGN_LEFT,
' ',
1,
null,
true /* this is important when using Console_Color */
);
foreach ($shells as $plugin => $shells) {
$plugin_label = MvcInflector::camelize(MvcInflector::underscore($plugin));
for ($i = 0; $i < count($shells); $i++) {
if ($i > 0) {
$plugin_label = ' ';
}
$shell_name = MvcInflector::camelize($shells[$i]);
$table->addRow(array(
$plugin_label,
Console_Color::convert('%_'.$shell_name.'%n')
));
}
$table->addSeparator();
}
$this->out($table->getTable());
$this->out('To get information about a shell try:');
$this->out("\n\twpmvc help shell <name_of_shell>");
}
|
Get a list of the available shells.
Also is executed if the wpmvc console is run with no arguments.
@param mixed $args
|
main
|
php
|
tombenner/wp-mvc
|
core/shells/help_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/help_shell.php
|
MIT
|
public function shell($args) {
list($name, $method) = $args;
if (empty($name)) {
$this->out('No shell given');
return;
}
try {
$shell = $this->get_shell_meta($name);
} catch (Exception $ex) {
$this->out('Error:');
$this->out($ex->getMessage());
return;
}
$this->nl();
$this->out(Console_Color::convert('%UShells > %n%U%9'.$shell->title.'%n'));
$this->nl();
$this->out($shell->doc);
$this->nl(2);
$this->out('Commands:');
$table = new Console_Table(
CONSOLE_TABLE_ALIGN_LEFT,
' ',
1,
null,
true // This is important when using Console_Color
);
if ($method == 'default') {
$method = '(default)';
}
if (!empty($method) && !empty($shell->methods[$method])) {
$table->addRow(array(Console_Color::convert('%9'.$method.'%n'), $shell->methods[$method]));
} else {
foreach ($shell->methods as $method => $doc) {
$table->addRow(array(Console_Color::convert('%9'.$method.'%n'), $doc));
$table->addSeparator();
}
}
$this->out($table->getTable());
}
|
Show documentation for a shell.
Usage:
wpmvc Help Shell <shell_name> [command_name]
wpmvc Help Shell Generate
wpmvc Help Shell Generate Scaffold
@param mixed $args
@return null
|
shell
|
php
|
tombenner/wp-mvc
|
core/shells/help_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/help_shell.php
|
MIT
|
public function activate_blog($blog_id = 1) {
if ($blog_id == 1) {
add_option('events_calendar_example_db_version', $this->db_version);
$this->create_tables();
}
else
{
switch_to_blog($blog_id);
add_option('events_calendar_example_db_version', $this->db_version);
$this->create_tables();
restore_current_blog();
}
}
|
activate_blog()
Setup the required tables for the plugin for $blog_id.
@param $blog_id - The id of the blog to work against
@return void
|
activate_blog
|
php
|
tombenner/wp-mvc
|
examples/events-calendar-example/events_calendar_example_loader.php
|
https://github.com/tombenner/wp-mvc/blob/master/examples/events-calendar-example/events_calendar_example_loader.php
|
MIT
|
public function deactivate_blog($blog_id = 1) {
if ($blog_id == 1) {
delete_option('events_calendar_example_db_version');
$this->delete_tables();
}
else
{
switch_to_blog($blog_id);
delete_option('events_calendar_example_db_version');
$this->delete_tables();
restore_current_blog();
}
}
|
deactivate_blog()
Remove the tables used by the plugin for $blog_id.
@param $blog_id - The id of the blog to work against
@return void
|
deactivate_blog
|
php
|
tombenner/wp-mvc
|
examples/events-calendar-example/events_calendar_example_loader.php
|
https://github.com/tombenner/wp-mvc/blob/master/examples/events-calendar-example/events_calendar_example_loader.php
|
MIT
|
private function create_tables() {
global $wpdb;
// this needs to occur at this level, and not in the
// constructor/init since we are switching blogs for multisite
$this->tables = array(
'events' => $wpdb->prefix.'events',
'events_speakers' => $wpdb->prefix.'events_speakers',
'speakers' => $wpdb->prefix.'speakers',
'venues' => $wpdb->prefix.'venues'
);
$sql = '
CREATE TABLE '.$this->tables['events'].' (
id int(11) NOT NULL auto_increment,
venue_id int(9) default NULL,
date date default NULL,
time time default NULL,
description text,
is_public tinyint(1) NOT NULL default 0,
PRIMARY KEY (id),
KEY venue_id (venue_id)
)';
dbDelta($sql);
$sql = '
CREATE TABLE '.$this->tables['events_speakers'].' (
id int(7) NOT NULL auto_increment,
event_id int(11) default NULL,
speaker_id int(11) default NULL,
PRIMARY KEY (id),
KEY event_id (event_id),
KEY speaker_id (speaker_id)
)';
dbDelta($sql);
$sql = '
CREATE TABLE '.$this->tables['speakers'].' (
id int(8) NOT NULL auto_increment,
first_name varchar(255) default NULL,
last_name varchar(255) default NULL,
url varchar(255) default NULL,
description text,
post_id BIGINT(20),
PRIMARY KEY (id),
KEY post_id (post_id)
)';
dbDelta($sql);
$sql = '
CREATE TABLE '.$this->tables['venues'].' (
id int(11) NOT NULL auto_increment,
name varchar(255) NOT NULL,
sort_name varchar(255) NOT NULL,
url varchar(255) default NULL,
description text,
address1 varchar(255) default NULL,
address2 varchar(255) default NULL,
city varchar(100) default NULL,
state varchar(100) default NULL,
zip varchar(20) default NULL,
post_id BIGINT(20),
PRIMARY KEY (id),
KEY post_id (post_id)
)';
dbDelta($sql);
$this->insert_example_data();
}
|
create_tables()
Create the required table for the plugin.
@return void
|
create_tables
|
php
|
tombenner/wp-mvc
|
examples/events-calendar-example/events_calendar_example_loader.php
|
https://github.com/tombenner/wp-mvc/blob/master/examples/events-calendar-example/events_calendar_example_loader.php
|
MIT
|
private function delete_tables() {
global $wpdb;
// this needs to occur at this level, and not in the
// constructor/init since we are switching blogs for multisite
$this->tables = array(
'events' => $wpdb->prefix.'events',
'events_speakers' => $wpdb->prefix.'events_speakers',
'speakers' => $wpdb->prefix.'speakers',
'venues' => $wpdb->prefix.'venues'
);
$sql = 'DROP TABLE IF EXISTS ' . $this->tables['events'];
$wpdb->query($sql);
$sql = 'DROP TABLE IF EXISTS ' . $this->tables['events_speakers'];
$wpdb->query($sql);
$sql = 'DROP TABLE IF EXISTS ' . $this->tables['speakers'];
$wpdb->query($sql);
$sql = 'DROP TABLE IF EXISTS ' . $this->tables['venues'];
$wpdb->query($sql);
}
|
delete_tables()
Delete the tables which are required by the plugin.
@return void
|
delete_tables
|
php
|
tombenner/wp-mvc
|
examples/events-calendar-example/events_calendar_example_loader.php
|
https://github.com/tombenner/wp-mvc/blob/master/examples/events-calendar-example/events_calendar_example_loader.php
|
MIT
|
private function insert_example_data() {
// Only insert the example data if no data already exists
$sql = '
SELECT
id
FROM
'.$this->tables['events'].'
LIMIT
1';
$data_exists = $this->wpdb->get_var($sql);
if ($data_exists) {
return false;
}
// Insert example data
$rows = array(
array(
'id' => 1,
'venue_id' => 2,
'date' => '2011-06-17',
'time' => '18:00:00',
'description' => '',
'is_public' => 1
),
array(
'id' => 2,
'venue_id' => 2,
'date' => '2011-11-10',
'time' => '15:43:00',
'description' => '',
'is_public' => 1
),
array(
'id' => 3,
'venue_id' => 1,
'date' => '2011-08-14',
'time' => '18:00:00',
'description' => 'Description about this event...',
'is_public' => 1
)
);
foreach($rows as $row) {
$this->wpdb->insert($this->tables['events'], $row);
}
$rows = array(
array(
'event_id' => 1,
'speaker_id' => 5
),
array(
'event_id' => 1,
'speaker_id' => 4
),
array(
'event_id' => 2,
'speaker_id' => 6
),
array(
'event_id' => 2,
'speaker_id' => 3
),
array(
'event_id' => 2,
'speaker_id' => 2
),
array(
'event_id' => 3,
'speaker_id' => 5
),
array(
'event_id' => 3,
'speaker_id' => 6
),
array(
'event_id' => 3,
'speaker_id' => 3
)
);
foreach($rows as $row) {
$this->wpdb->insert($this->tables['events_speakers'], $row);
}
$rows = array(
array(
'id' => 1,
'first_name' => 'Maurice',
'last_name' => 'Deebank',
'url' => 'http://maurice.com',
'description' => 'Maurice\'s bio...'
),
array(
'id' => 2,
'first_name' => 'Gary',
'last_name' => 'Ainge',
'url' => 'http://gary.com',
'description' => 'Gary\'s bio...'
),
array(
'id' => 3,
'first_name' => 'Martin',
'last_name' => 'Duffy',
'url' => 'http://martin.com',
'description' => 'Martin\'s bio...'
),
array(
'id' => 4,
'first_name' => 'Marco',
'last_name' => 'Thomas',
'url' => 'http://marco.com',
'description' => 'Marco\'s bio...'
),
array(
'id' => 5,
'first_name' => 'Nick',
'last_name' => 'Gilbert',
'url' => 'http://nick.com',
'description' => 'Nick\'s bio...'
),
array(
'id' => 6,
'first_name' => 'Mick',
'last_name' => 'Lloyd',
'url' => 'http://mick.com',
'description' => 'Mick\'s bio...'
)
);
foreach($rows as $row) {
$this->wpdb->insert($this->tables['speakers'], $row);
}
$rows = array(
array(
'id' => 1,
'name' => 'Cabell Auditorium',
'sort_name' => 'Cabell Auditorium',
'url' => 'http://cabellauditorium.com',
'description' => '',
'address1' => '10 E 15th St',
'address2' => '',
'city' => 'New York',
'state' => 'NY',
'zip' => '10003'
),
array(
'id' => 2,
'name' => 'Farveson Hall',
'sort_name' => 'Farveson Hall',
'url' => 'http://farvesonhall.org',
'description' => '',
'address1' => '216 W 21st St',
'address2' => '',
'city' => 'New York',
'state' => 'NY',
'zip' => '10011'
)
);
foreach($rows as $row) {
$this->wpdb->insert($this->tables['venues'], $row);
}
}
|
insert_example_data()
Insert some dummy data
@return void
|
insert_example_data
|
php
|
tombenner/wp-mvc
|
examples/events-calendar-example/events_calendar_example_loader.php
|
https://github.com/tombenner/wp-mvc/blob/master/examples/events-calendar-example/events_calendar_example_loader.php
|
MIT
|
public function action_index()
{
return Response::forge(View::forge('welcome/index'));
}
|
The basic welcome message
@access public
@return Response
|
action_index
|
php
|
fuel/fuel
|
fuel/app/classes/controller/welcome.php
|
https://github.com/fuel/fuel/blob/master/fuel/app/classes/controller/welcome.php
|
MIT
|
public function action_hello()
{
return Response::forge(Presenter::forge('welcome/hello'));
}
|
A typical "Hello, Bob!" type example. This uses a Presenter to
show how to use them.
@access public
@return Response
|
action_hello
|
php
|
fuel/fuel
|
fuel/app/classes/controller/welcome.php
|
https://github.com/fuel/fuel/blob/master/fuel/app/classes/controller/welcome.php
|
MIT
|
public function action_404()
{
return Response::forge(Presenter::forge('welcome/404'), 404);
}
|
The 404 action for the application.
@access public
@return Response
|
action_404
|
php
|
fuel/fuel
|
fuel/app/classes/controller/welcome.php
|
https://github.com/fuel/fuel/blob/master/fuel/app/classes/controller/welcome.php
|
MIT
|
public function view()
{
$messages = array('Aw, crap!', 'Bloody Hell!', 'Uh Oh!', 'Nope, not here.', 'Huh?');
$this->title = $messages[array_rand($messages)];
}
|
Prepare the view data, keeping this in here helps clean up
the controller.
@return void
|
view
|
php
|
fuel/fuel
|
fuel/app/classes/presenter/welcome/404.php
|
https://github.com/fuel/fuel/blob/master/fuel/app/classes/presenter/welcome/404.php
|
MIT
|
public function view()
{
$this->name = $this->request()->param('name', 'World');
}
|
Prepare the view data, keeping this in here helps clean up
the controller.
@return void
|
view
|
php
|
fuel/fuel
|
fuel/app/classes/presenter/welcome/hello.php
|
https://github.com/fuel/fuel/blob/master/fuel/app/classes/presenter/welcome/hello.php
|
MIT
|
public static function run($speech = null)
{
if ( ! isset($speech))
{
$speech = 'KILL ALL HUMANS!';
}
$eye = \Cli::color("*", 'red');
return \Cli::color("
\"{$speech}\"
_____ /
/_____\\", 'blue')."\n"
.\Cli::color(" ____[\\", 'blue').$eye.\Cli::color('---', 'blue').$eye.\Cli::color('/]____', 'blue')."\n"
.\Cli::color(" /\\ #\\ \\_____/ /# /\\
/ \\# \\_.---._/ #/ \\
/ /|\\ | | /|\\ \\
/___/ | | | | | | \\___\\
| | | | |---| | | | |
|__| \\_| |_#_| |_/ |__|
//\\\\ <\\ _//^\\\\_ /> //\\\\
\\||/ |\\//// \\\\\\\\/| \\||/
| | | |
|---| |---|
|---| |---|
| | | |
|___| |___|
/ \\ / \\
|_____| |_____|
|HHHHH| |HHHHH|", 'blue');
}
|
This method gets ran when a valid method name is not used in the command.
Usage (from command line):
php oil r robots
or
php oil r robots "Kill all Mice"
@return string
|
run
|
php
|
fuel/fuel
|
fuel/app/tasks/robots.php
|
https://github.com/fuel/fuel/blob/master/fuel/app/tasks/robots.php
|
MIT
|
public static function protect()
{
$eye = \Cli::color("*", 'green');
return \Cli::color("
\"PROTECT ALL HUMANS\"
_____ /
/_____\\", 'blue')."\n"
.\Cli::color(" ____[\\", 'blue').$eye.\Cli::color('---', 'blue').$eye.\Cli::color('/]____', 'blue')."\n"
.\Cli::color(" /\\ #\\ \\_____/ /# /\\
/ \\# \\_.---._/ #/ \\
/ /|\\ | | /|\\ \\
/___/ | | | | | | \\___\\
| | | | |---| | | | |
|__| \\_| |_#_| |_/ |__|
//\\\\ <\\ _//^\\\\_ /> //\\\\
\\||/ |\\//// \\\\\\\\/| \\||/
| | | |
|---| |---|
|---| |---|
| | | |
|___| |___|
/ \\ / \\
|_____| |_____|
|HHHHH| |HHHHH|", 'blue');
}
|
An example method that is here just to show the various uses of tasks.
Usage (from command line):
php oil r robots:protect
@return string
|
protect
|
php
|
fuel/fuel
|
fuel/app/tasks/robots.php
|
https://github.com/fuel/fuel/blob/master/fuel/app/tasks/robots.php
|
MIT
|
private static function convertSelfObjectInArray(array $values): array
{
foreach ($values as $key => $value) {
if (is_array($value)) {
$values[$key] = self::convertSelfObjectInArray($value);
continue;
}
if ($value instanceof self) {
$values[$key] = $value->convertToArray();
}
}
return $values;
}
|
@param mixed[] $values
@return string[]|string[][]
|
convertSelfObjectInArray
|
php
|
artesaos/seotools
|
src/SEOTools/JsonLd.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/JsonLd.php
|
MIT
|
public function __construct(array $config = [])
{
$this->config = $config;
}
|
Create a new OpenGraph instance.
@param array $config config
@return void
|
__construct
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
protected function eachProperties(
array $properties,
$prefix = null,
$ogPrefix = true
) {
$html = [];
foreach ($properties as $property => $value) {
// multiple properties
if (is_array($value)) {
if (is_string($property)){
$subListPrefix = $prefix.":".$property;
$subList = $this->eachProperties($value, $subListPrefix, false);
} else {
$subListPrefix = (is_string($property)) ? $property : $prefix;
$subList = $this->eachProperties($value, $subListPrefix);
}
$html[] = $subList;
} else {
if (is_string($prefix)) {
$key = (is_string($property)) ?
$prefix.':'.$property :
$prefix;
} else {
$key = $property;
}
// if empty jump to next
if (empty($value)) {
continue;
}
$html[] = $this->makeTag($key, $value, $ogPrefix);
}
}
return implode($html);
}
|
Make list of open graph tags.
@param array $properties array of properties
@param null|string $prefix prefix of property
@param bool $ogPrefix opengraph prefix
@return string
|
eachProperties
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
protected function makeTag($key = null, $value = null, $ogPrefix = false)
{
return sprintf(
'<meta property="%s%s" content="%s">%s',
$ogPrefix ? $this->og_prefix : '',
strip_tags($key),
$this->cleanTagValue($value),
PHP_EOL
);
}
|
Make a og tag.
@param string $key meta property key
@param string $value meta property value
@param bool $ogPrefix opengraph prefix
@return string
|
makeTag
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
protected function cleanTagValue($value)
{
// Safety
$value = str_replace(['http-equiv=', 'url='], '', $value);
// Escape double quotes
$value = htmlspecialchars($value, ENT_QUOTES, null, false);
// Clean
$value = strip_tags($value);
return $value;
}
|
Clean og tag value
@param string $value meta property value
@return string
|
cleanTagValue
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
protected function setupDefaults()
{
$defaults = (isset($this->config['defaults'])) ?
$this->config['defaults'] :
[];
foreach ($defaults as $key => $value) {
if ($key === 'images') {
if (empty($this->images)) {
$this->images = $value;
}
} elseif ($key === 'url' && empty($value)) {
if ($value === null) {
$this->addProperty('url', $this->url ?: app('url')->current());
} elseif ($this->url) {
$this->addProperty('url', $this->url);
}
} elseif (! empty($value) && ! array_key_exists($key, $this->properties)) {
$this->addProperty($key, $value);
}
}
}
|
Add or update property.
@return void
|
setupDefaults
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
public function setPlace($attributes = [])
{
$validkeys = [
'location:latitude',
'location:longitude',
];
$this->setProperties('place', 'placeProperties', $attributes, $validkeys);
return $this;
}
|
Set place properties.
@param array $attributes opengraph place attributes
@return OpenGraphContract
|
setPlace
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
public function setProduct($attributes = [])
{
$validkeys = [
// Required
'brand',
'availability',
'condition',
// Conditionally required
'locale',
'plural_title',
// Conditionally required: https://developers.facebook.com/docs/payments/product/
'price:amount', // Required if Static Pricing & not Dynamic Pricing
'price:currency', // Required if Static Pricing & not Dynamic Pricing
// Optional
'catalog_id',
'item_group_id',
'category',
'gender',
'gtin',
'isbn',
'mfr_part_no',
'retailer_item_id',
'sale_price:amount',
'sale_price:currency',
'sale_price_dates:start',
'sale_price_dates:end',
// Optional - extra
'custom_label_0',
'custom_label_1',
'custom_label_2',
'custom_label_3',
'custom_label_4',
// Deprecated
'original_price:amount',
'original_price:currency',
'pretax_price:amount',
'pretax_price:currency',
'shipping_cost:amount',
'shipping_cost:currency',
'weight:value',
'weight:units',
'shipping_weight:value',
'shipping_weight:units',
];
$this->setProperties('product', 'productProperties', $attributes, $validkeys);
return $this;
}
|
Set product properties.
Reference: https://developers.facebook.com/docs/marketing-api/catalog/reference/#example-feeds
@param array $attributes opengraph product attributes
@return OpenGraphContract
|
setProduct
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
protected function cleanProperties($attributes = [], $validKeys = [])
{
$array = [];
foreach ($attributes as $attribute => $value) {
if (in_array($attribute, $validKeys)) {
$array[$attribute] = $value;
}
}
return $array;
}
|
Clean invalid properties.
@param array $attributes attributes input
@param string[] $validKeys keys that are allowed
@return array
|
cleanProperties
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
protected function setProperties(
$type = null,
$key = null,
$attributes = [],
$validKeys = []
) {
if (isset($this->properties['type']) && $this->properties['type'] == $type) {
foreach ($attributes as $attribute => $value) {
if (in_array($attribute, $validKeys)) {
$this->{$key}[$attribute] = $value;
}
}
}
}
|
Set properties.
@param string $type type of og:type
@param string $key variable key
@param array $attributes inputted opengraph attributes
@param string[] $validKeys valid opengraph attributes
@return void
|
setProperties
|
php
|
artesaos/seotools
|
src/SEOTools/OpenGraph.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/OpenGraph.php
|
MIT
|
public function setAmpHtml($url)
{
$this->amphtml = $url;
return $this;
}
|
Sets the AMP html URL.
@param string $url
@return MetaTagsContract
|
setAmpHtml
|
php
|
artesaos/seotools
|
src/SEOTools/SEOMeta.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/SEOMeta.php
|
MIT
|
public function setRobots($robots)
{
$this->robots = $robots;
return $this;
}
|
Sets the meta robots.
@param string $robots
@return MetaTagsContract
|
setRobots
|
php
|
artesaos/seotools
|
src/SEOTools/SEOMeta.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/SEOMeta.php
|
MIT
|
public function getAmpHtml()
{
return $this->amphtml;
}
|
Get the AMP html URL.
@return string
|
getAmpHtml
|
php
|
artesaos/seotools
|
src/SEOTools/SEOMeta.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/SEOMeta.php
|
MIT
|
protected function parseTitle($title)
{
$default = $this->getDefaultTitle();
if (empty($default)) {
return $title;
}
$defaultBefore = $this->config->get('defaults.titleBefore', false);
return $defaultBefore ? $default.$this->getTitleSeparator().$title : $title.$this->getTitleSeparator().$default;
}
|
Get parsed title.
@param string $title
@return string
|
parseTitle
|
php
|
artesaos/seotools
|
src/SEOTools/SEOMeta.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/SEOMeta.php
|
MIT
|
protected function eachValue(array $values, $prefix = null)
{
foreach ($values as $key => $value):
if (is_array($value)):
$this->eachValue($value, $key); else:
if (is_numeric($key)):
$key = $prefix.$key; elseif (is_string($prefix)):
$key = $prefix.':'.$key;
endif;
$this->html[] = $this->makeTag($key, $value);
endif;
endforeach;
}
|
Make tags.
@param array $values
@param null|string $prefix
@internal param array $properties
|
eachValue
|
php
|
artesaos/seotools
|
src/SEOTools/TwitterCards.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/TwitterCards.php
|
MIT
|
private function makeTag($key, $value)
{
return sprintf(
'<meta name="%s" content="%s">',
$this->prefix.strip_tags($key),
$this->cleanTagValue($value)
);
}
|
@param string $key
@param $value
@return string
@internal param string $values
|
makeTag
|
php
|
artesaos/seotools
|
src/SEOTools/TwitterCards.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/TwitterCards.php
|
MIT
|
protected function cleanTagValue($value)
{
// Safety
$value = str_replace(['http-equiv=', 'url='], '', $value);
// Escape double quotes
$value = htmlspecialchars($value, ENT_QUOTES, null, false);
// Clean
$value = strip_tags($value);
return $value;
}
|
Clean tag value
@param string $value meta content value
@return string
|
cleanTagValue
|
php
|
artesaos/seotools
|
src/SEOTools/TwitterCards.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/TwitterCards.php
|
MIT
|
public function addImage($image)
{
foreach ((array) $image as $url) {
$this->images[] = $url;
}
return $this;
}
|
{@inheritdoc}
@deprecated use setImage($image) instead
|
addImage
|
php
|
artesaos/seotools
|
src/SEOTools/TwitterCards.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/TwitterCards.php
|
MIT
|
public function setImages($images)
{
$this->images = [];
return $this->addImage($images);
}
|
{@inheritdoc}
@deprecated use setImage($image) instead
|
setImages
|
php
|
artesaos/seotools
|
src/SEOTools/TwitterCards.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/TwitterCards.php
|
MIT
|
public function register()
{
$this->app->singleton('seotools.metatags', function ($app) {
return new SEOMeta(new Config($app['config']->get('seotools.meta', [])));
});
$this->app->singleton('seotools.opengraph', function ($app) {
return new OpenGraph($app['config']->get('seotools.opengraph', []));
});
$this->app->singleton('seotools.twitter', function ($app) {
return new TwitterCards($app['config']->get('seotools.twitter.defaults', []));
});
$this->app->singleton('seotools.json-ld', function ($app) {
return new JsonLd($app['config']->get('seotools.json-ld.defaults', []));
});
$this->app->singleton('seotools.json-ld-multi', function ($app) {
return new JsonLdMulti($app['config']->get('seotools.json-ld.defaults', []));
});
$this->app->singleton('seotools', function () {
return new SEOTools();
});
$this->app->bind(Contracts\MetaTags::class, 'seotools.metatags');
$this->app->bind(Contracts\OpenGraph::class, 'seotools.opengraph');
$this->app->bind(Contracts\TwitterCards::class, 'seotools.twitter');
$this->app->bind(Contracts\JsonLd::class, 'seotools.json-ld');
$this->app->bind(Contracts\JsonLdMulti::class, 'seotools.json-ld-multi');
$this->app->bind(Contracts\SEOTools::class, 'seotools');
}
|
Register the service provider.
@return void
|
register
|
php
|
artesaos/seotools
|
src/SEOTools/Providers/SEOToolsServiceProvider.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/Providers/SEOToolsServiceProvider.php
|
MIT
|
protected function loadSEO(SEOFriendly $friendly)
{
$SEO = $this->seo();
$friendly->loadSEO($SEO);
return $SEO;
}
|
@param SEOFriendly $friendly
@return \Artesaos\SEOTools\Contracts\SEOTools
|
loadSEO
|
php
|
artesaos/seotools
|
src/SEOTools/Traits/SEOTools.php
|
https://github.com/artesaos/seotools/blob/master/src/SEOTools/Traits/SEOTools.php
|
MIT
|
public function test_container_are_provided($contract, $concreteClass)
{
$this->assertInstanceOf(
$contract,
$this->app[$concreteClass]
);
}
|
Verify if classes are in service container.
@dataProvider bindsListProvider
@param string $contract
@param string $concreteClass
|
test_container_are_provided
|
php
|
artesaos/seotools
|
tests/SEOTools/SEOToolsServiceProviderTest.php
|
https://github.com/artesaos/seotools/blob/master/tests/SEOTools/SEOToolsServiceProviderTest.php
|
MIT
|
public function __construct(Channel $channel,
$method,
$deserialize,
array $options = [])
{
if (array_key_exists('timeout', $options) &&
is_numeric($timeout = $options['timeout'])
) {
$now = Timeval::now();
$delta = new Timeval($timeout);
$deadline = $now->add($delta);
} else {
$deadline = Timeval::infFuture();
}
$this->call = new Call($channel, $method, $deadline);
$this->deserialize = $deserialize;
$this->metadata = null;
$this->trailing_metadata = null;
if (array_key_exists('call_credentials_callback', $options) &&
is_callable($call_credentials_callback =
$options['call_credentials_callback'])
) {
$call_credentials = CallCredentials::createFromPlugin(
$call_credentials_callback
);
$this->call->setCredentials($call_credentials);
}
}
|
Create a new Call wrapper object.
@param Channel $channel The channel to communicate on
@param string $method The method to call on the
remote server
@param callback $deserialize A callback function to deserialize
the response
@param array $options Call options (optional)
|
__construct
|
php
|
grpc/grpc-php
|
src/lib/AbstractCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/AbstractCall.php
|
Apache-2.0
|
public function getMetadata()
{
return $this->metadata;
}
|
@return mixed The metadata sent by the server
|
getMetadata
|
php
|
grpc/grpc-php
|
src/lib/AbstractCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/AbstractCall.php
|
Apache-2.0
|
public function getTrailingMetadata()
{
return $this->trailing_metadata;
}
|
@return mixed The trailing metadata sent by the server
|
getTrailingMetadata
|
php
|
grpc/grpc-php
|
src/lib/AbstractCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/AbstractCall.php
|
Apache-2.0
|
public function getPeer()
{
return $this->call->getPeer();
}
|
@return string The URI of the endpoint
|
getPeer
|
php
|
grpc/grpc-php
|
src/lib/AbstractCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/AbstractCall.php
|
Apache-2.0
|
protected function _serializeMessage($data)
{
// Proto3 implementation
return $data->serializeToString();
}
|
Serialize a message to the protobuf binary format.
@param mixed $data The Protobuf message
@return string The protobuf binary format
|
_serializeMessage
|
php
|
grpc/grpc-php
|
src/lib/AbstractCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/AbstractCall.php
|
Apache-2.0
|
protected function _deserializeResponse($value)
{
if ($value === null) {
return;
}
list($className, $deserializeFunc) = $this->deserialize;
$obj = new $className();
$obj->mergeFromString($value);
return $obj;
}
|
Deserialize a response value to an object.
@param string $value The binary value to deserialize
@return mixed The deserialized value
|
_deserializeResponse
|
php
|
grpc/grpc-php
|
src/lib/AbstractCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/AbstractCall.php
|
Apache-2.0
|
public function setCallCredentials($call_credentials)
{
$this->call->setCredentials($call_credentials);
}
|
Set the CallCredentials for the underlying Call.
@param CallCredentials $call_credentials The CallCredentials object
|
setCallCredentials
|
php
|
grpc/grpc-php
|
src/lib/AbstractCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/AbstractCall.php
|
Apache-2.0
|
public function __construct($hostname, $opts, $channel = null)
{
if (!method_exists('Grpc\ChannelCredentials', 'isDefaultRootsPemSet') ||
!ChannelCredentials::isDefaultRootsPemSet()) {
$ssl_roots = file_get_contents(
dirname(__FILE__).'/../../etc/roots.pem'
);
ChannelCredentials::setDefaultRootsPem($ssl_roots);
}
$this->hostname = $hostname;
$this->update_metadata = null;
if (isset($opts['update_metadata'])) {
if (is_callable($opts['update_metadata'])) {
$this->update_metadata = $opts['update_metadata'];
}
unset($opts['update_metadata']);
}
if (!empty($opts['grpc.ssl_target_name_override'])) {
$this->hostname_override = $opts['grpc.ssl_target_name_override'];
}
if (isset($opts['grpc_call_invoker'])) {
$this->call_invoker = $opts['grpc_call_invoker'];
unset($opts['grpc_call_invoker']);
$channel_opts = $this->updateOpts($opts);
// If the grpc_call_invoker is defined, use the channel created by the call invoker.
$this->channel = $this->call_invoker->createChannelFactory($hostname, $channel_opts);
return;
}
$this->call_invoker = new DefaultCallInvoker();
if ($channel) {
if (!is_a($channel, 'Grpc\Channel') &&
!is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
throw new \Exception('The channel argument is not a Channel object '.
'or an InterceptorChannel object created by '.
'Interceptor::intercept($channel, Interceptor|Interceptor[] $interceptors)');
}
$this->channel = $channel;
return;
}
$this->channel = static::getDefaultChannel($hostname, $opts);
}
|
@param string $hostname
@param array $opts
- 'update_metadata': (optional) a callback function which takes in a
metadata array, and returns an updated metadata array
- 'grpc.primary_user_agent': (optional) a user-agent string
@param Channel|InterceptorChannel $channel An already created Channel or InterceptorChannel object (optional)
|
__construct
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
public static function getDefaultChannel($hostname, array $opts)
{
$channel_opts = self::updateOpts($opts);
return new Channel($hostname, $channel_opts);
}
|
Creates and returns the default Channel
@param array $opts Channel constructor options
@return Channel The channel
|
getDefaultChannel
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
public function getTarget()
{
return $this->channel->getTarget();
}
|
@return string The URI of the endpoint
|
getTarget
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
public function getConnectivityState($try_to_connect = false)
{
return $this->channel->getConnectivityState($try_to_connect);
}
|
@param bool $try_to_connect (optional)
@return int The grpc connectivity state
|
getConnectivityState
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
public function waitForReady($timeout)
{
$new_state = $this->getConnectivityState(true);
if ($this->_checkConnectivityState($new_state)) {
return true;
}
$now = Timeval::now();
$delta = new Timeval($timeout);
$deadline = $now->add($delta);
while ($this->channel->watchConnectivityState($new_state, $deadline)) {
// state has changed before deadline
$new_state = $this->getConnectivityState();
if ($this->_checkConnectivityState($new_state)) {
return true;
}
}
// deadline has passed
$new_state = $this->getConnectivityState();
return $this->_checkConnectivityState($new_state);
}
|
@param int $timeout in microseconds
@return bool true if channel is ready
@throws Exception if channel is in FATAL_ERROR state
|
waitForReady
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
public function close()
{
$this->channel->close();
}
|
Close the communication channel associated with this stub.
|
close
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _checkConnectivityState($new_state)
{
if ($new_state == \Grpc\CHANNEL_READY) {
return true;
}
if ($new_state == \Grpc\CHANNEL_FATAL_FAILURE) {
throw new \Exception('Failed to connect to server');
}
return false;
}
|
@param $new_state Connect state
@return bool true if state is CHANNEL_READY
@throws Exception if state is CHANNEL_FATAL_FAILURE
|
_checkConnectivityState
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _get_jwt_aud_uri($method)
{
// TODO(jtattermusch): This is not the correct implementation
// of extracting JWT "aud" claim. We should rely on
// grpc_metadata_credentials_plugin which
// also provides the correct value of "aud" claim
// in the grpc_auth_metadata_context.service_url field.
// Trying to do the construction of "aud" field ourselves
// is bad.
$last_slash_idx = strrpos($method, '/');
if ($last_slash_idx === false) {
throw new \InvalidArgumentException(
'service name must have a slash'
);
}
$service_name = substr($method, 0, $last_slash_idx);
if ($this->hostname_override) {
$hostname = $this->hostname_override;
} else {
$hostname = $this->hostname;
}
// Remove the port if it is 443
// See https://github.com/grpc/grpc/blob/07c9f7a36b2a0d34fcffebc85649cf3b8c339b5d/src/core/lib/security/transport/client_auth_filter.cc#L205
if ((strlen($hostname) > 4) && (substr($hostname, -4) === ":443")) {
$hostname = substr($hostname, 0, -4);
}
return 'https://'.$hostname.$service_name;
}
|
constructs the auth uri for the jwt.
@param string $method The method string
@return string The URL string
|
_get_jwt_aud_uri
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _validate_and_normalize_metadata($metadata)
{
$metadata_copy = [];
foreach ($metadata as $key => $value) {
if (!preg_match('/^[.A-Za-z\d_-]+$/', $key)) {
throw new \InvalidArgumentException(
'Metadata keys must be nonempty strings containing only '.
'alphanumeric characters, hyphens, underscores and dots'
);
}
$metadata_copy[strtolower($key)] = $value;
}
return $metadata_copy;
}
|
validate and normalize the metadata array.
@param array $metadata The metadata map
@return array $metadata Validated and key-normalized metadata map
@throws InvalidArgumentException if key contains invalid characters
|
_validate_and_normalize_metadata
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _GrpcUnaryUnary($channel)
{
return function ($method,
$argument,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
$call = $this->call_invoker->UnaryCall(
$channel,
$method,
$deserialize,
$options
);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
$metadata = call_user_func(
$this->update_metadata,
$metadata,
$jwt_aud_uri
);
}
$metadata = $this->_validate_and_normalize_metadata(
$metadata
);
$call->start($argument, $metadata, $options);
return $call;
};
}
|
Create a function which can be used to create UnaryCall
@param Channel|InterceptorChannel $channel
@param callable $deserialize A function that deserializes the response
@return \Closure
|
_GrpcUnaryUnary
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _GrpcStreamUnary($channel)
{
return function ($method,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
$call = $this->call_invoker->ClientStreamingCall(
$channel,
$method,
$deserialize,
$options
);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
$metadata = call_user_func(
$this->update_metadata,
$metadata,
$jwt_aud_uri
);
}
$metadata = $this->_validate_and_normalize_metadata(
$metadata
);
$call->start($metadata);
return $call;
};
}
|
Create a function which can be used to create ServerStreamingCall
@param Channel|InterceptorChannel $channel
@param callable $deserialize A function that deserializes the response
@return \Closure
|
_GrpcStreamUnary
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _GrpcUnaryStream($channel)
{
return function ($method,
$argument,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
$call = $this->call_invoker->ServerStreamingCall(
$channel,
$method,
$deserialize,
$options
);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
$metadata = call_user_func(
$this->update_metadata,
$metadata,
$jwt_aud_uri
);
}
$metadata = $this->_validate_and_normalize_metadata(
$metadata
);
$call->start($argument, $metadata, $options);
return $call;
};
}
|
Create a function which can be used to create ClientStreamingCall
@param Channel|InterceptorChannel $channel
@param callable $deserialize A function that deserializes the response
@return \Closure
|
_GrpcUnaryStream
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _GrpcStreamStream($channel)
{
return function ($method,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
$call = $this->call_invoker->BidiStreamingCall(
$channel,
$method,
$deserialize,
$options
);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
$metadata = call_user_func(
$this->update_metadata,
$metadata,
$jwt_aud_uri
);
}
$metadata = $this->_validate_and_normalize_metadata(
$metadata
);
$call->start($metadata);
return $call;
};
}
|
Create a function which can be used to create BidiStreamingCall
@param Channel|InterceptorChannel $channel
@param callable $deserialize A function that deserializes the response
@return \Closure
|
_GrpcStreamStream
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _UnaryUnaryCallFactory($channel)
{
if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
return function ($method,
$argument,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
return $channel->getInterceptor()->interceptUnaryUnary(
$method,
$argument,
$deserialize,
$this->_UnaryUnaryCallFactory($channel->getNext()),
$metadata,
$options
);
};
}
return $this->_GrpcUnaryUnary($channel);
}
|
Create a function which can be used to create UnaryCall
@param Channel|InterceptorChannel $channel
@param callable $deserialize A function that deserializes the response
@return \Closure
|
_UnaryUnaryCallFactory
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _UnaryStreamCallFactory($channel)
{
if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
return function ($method,
$argument,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
return $channel->getInterceptor()->interceptUnaryStream(
$method,
$argument,
$deserialize,
$this->_UnaryStreamCallFactory($channel->getNext()),
$metadata,
$options
);
};
}
return $this->_GrpcUnaryStream($channel);
}
|
Create a function which can be used to create ServerStreamingCall
@param Channel|InterceptorChannel $channel
@param callable $deserialize A function that deserializes the response
@return \Closure
|
_UnaryStreamCallFactory
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _StreamUnaryCallFactory($channel)
{
if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
return function ($method,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
return $channel->getInterceptor()->interceptStreamUnary(
$method,
$deserialize,
$this->_StreamUnaryCallFactory($channel->getNext()),
$metadata,
$options
);
};
}
return $this->_GrpcStreamUnary($channel);
}
|
Create a function which can be used to create ClientStreamingCall
@param Channel|InterceptorChannel $channel
@param callable $deserialize A function that deserializes the response
@return \Closure
|
_StreamUnaryCallFactory
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
private function _StreamStreamCallFactory($channel)
{
if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
return function ($method,
$deserialize,
array $metadata = [],
array $options = []) use ($channel) {
return $channel->getInterceptor()->interceptStreamStream(
$method,
$deserialize,
$this->_StreamStreamCallFactory($channel->getNext()),
$metadata,
$options
);
};
}
return $this->_GrpcStreamStream($channel);
}
|
Create a function which can be used to create BidiStreamingCall
@param Channel|InterceptorChannel $channel
@param callable $deserialize A function that deserializes the response
@return \Closure
|
_StreamStreamCallFactory
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
protected function _simpleRequest(
$method,
$argument,
$deserialize,
array $metadata = [],
array $options = []
) {
$call_factory = $this->_UnaryUnaryCallFactory($this->channel);
$call = $call_factory($method, $argument, $deserialize, $metadata, $options);
return $call;
}
|
Call a remote method that takes a single argument and has a
single output.
@param string $method The name of the method to call
@param mixed $argument The argument to the method
@param callable $deserialize A function that deserializes the response
@param array $metadata A metadata map to send to the server
(optional)
@param array $options An array of options (optional)
@return UnaryCall The active call object
|
_simpleRequest
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
protected function _clientStreamRequest(
$method,
$deserialize,
array $metadata = [],
array $options = []
) {
$call_factory = $this->_StreamUnaryCallFactory($this->channel);
$call = $call_factory($method, $deserialize, $metadata, $options);
return $call;
}
|
Call a remote method that takes a stream of arguments and has a single
output.
@param string $method The name of the method to call
@param callable $deserialize A function that deserializes the response
@param array $metadata A metadata map to send to the server
(optional)
@param array $options An array of options (optional)
@return ClientStreamingCall The active call object
|
_clientStreamRequest
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
protected function _serverStreamRequest(
$method,
$argument,
$deserialize,
array $metadata = [],
array $options = []
) {
$call_factory = $this->_UnaryStreamCallFactory($this->channel);
$call = $call_factory($method, $argument, $deserialize, $metadata, $options);
return $call;
}
|
Call a remote method that takes a single argument and returns a stream
of responses.
@param string $method The name of the method to call
@param mixed $argument The argument to the method
@param callable $deserialize A function that deserializes the responses
@param array $metadata A metadata map to send to the server
(optional)
@param array $options An array of options (optional)
@return ServerStreamingCall The active call object
|
_serverStreamRequest
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
protected function _bidiRequest(
$method,
$deserialize,
array $metadata = [],
array $options = []
) {
$call_factory = $this->_StreamStreamCallFactory($this->channel);
$call = $call_factory($method, $deserialize, $metadata, $options);
return $call;
}
|
Call a remote method with messages streaming in both directions.
@param string $method The name of the method to call
@param callable $deserialize A function that deserializes the responses
@param array $metadata A metadata map to send to the server
(optional)
@param array $options An array of options (optional)
@return BidiStreamingCall The active call object
|
_bidiRequest
|
php
|
grpc/grpc-php
|
src/lib/BaseStub.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BaseStub.php
|
Apache-2.0
|
public function start(array $metadata = [])
{
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
]);
}
|
Start the call.
@param array $metadata Metadata to send with the call, if applicable
(optional)
|
start
|
php
|
grpc/grpc-php
|
src/lib/BidiStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BidiStreamingCall.php
|
Apache-2.0
|
public function read()
{
$batch = [OP_RECV_MESSAGE => true];
if ($this->metadata === null) {
$batch[OP_RECV_INITIAL_METADATA] = true;
}
$read_event = $this->call->startBatch($batch);
if ($this->metadata === null) {
$this->metadata = $read_event->metadata;
}
return $this->_deserializeResponse($read_event->message);
}
|
Reads the next value from the server.
@return mixed The next value from the server, or null if there is none
|
read
|
php
|
grpc/grpc-php
|
src/lib/BidiStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BidiStreamingCall.php
|
Apache-2.0
|
public function write($data, array $options = [])
{
$message_array = ['message' => $this->_serializeMessage($data)];
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
OP_SEND_MESSAGE => $message_array,
]);
}
|
Write a single message to the server. This cannot be called after
writesDone is called.
@param ByteBuffer $data The data to write
@param array $options An array of options, possible keys:
'flags' => a number (optional)
|
write
|
php
|
grpc/grpc-php
|
src/lib/BidiStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BidiStreamingCall.php
|
Apache-2.0
|
public function writesDone()
{
$this->call->startBatch([
OP_SEND_CLOSE_FROM_CLIENT => true,
]);
}
|
Indicate that no more writes will be sent.
|
writesDone
|
php
|
grpc/grpc-php
|
src/lib/BidiStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BidiStreamingCall.php
|
Apache-2.0
|
public function getStatus()
{
$status_event = $this->call->startBatch([
OP_RECV_STATUS_ON_CLIENT => true,
]);
$this->trailing_metadata = $status_event->status->metadata;
return $status_event->status;
}
|
Wait for the server to send the status, and return it.
@return \stdClass The status object, with integer $code, string
$details, and array $metadata members
|
getStatus
|
php
|
grpc/grpc-php
|
src/lib/BidiStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/BidiStreamingCall.php
|
Apache-2.0
|
public function start(array $metadata = [])
{
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
]);
}
|
Start the call.
@param array $metadata Metadata to send with the call, if applicable
(optional)
|
start
|
php
|
grpc/grpc-php
|
src/lib/ClientStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/ClientStreamingCall.php
|
Apache-2.0
|
public function write($data, array $options = [])
{
$message_array = ['message' => $this->_serializeMessage($data)];
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
OP_SEND_MESSAGE => $message_array,
]);
}
|
Write a single message to the server. This cannot be called after
wait is called.
@param ByteBuffer $data The data to write
@param array $options An array of options, possible keys:
'flags' => a number (optional)
|
write
|
php
|
grpc/grpc-php
|
src/lib/ClientStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/ClientStreamingCall.php
|
Apache-2.0
|
public function wait()
{
$event = $this->call->startBatch([
OP_SEND_CLOSE_FROM_CLIENT => true,
OP_RECV_INITIAL_METADATA => true,
OP_RECV_MESSAGE => true,
OP_RECV_STATUS_ON_CLIENT => true,
]);
$this->metadata = $event->metadata;
$status = $event->status;
$this->trailing_metadata = $status->metadata;
return [$this->_deserializeResponse($event->message), $status];
}
|
Wait for the server to respond with data and a status.
@return array [response data, status]
|
wait
|
php
|
grpc/grpc-php
|
src/lib/ClientStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/ClientStreamingCall.php
|
Apache-2.0
|
public static function intercept($channel, $interceptors)
{
if (is_array($interceptors)) {
for ($i = count($interceptors) - 1; $i >= 0; $i--) {
$channel = new Internal\InterceptorChannel($channel, $interceptors[$i]);
}
} else {
$channel = new Internal\InterceptorChannel($channel, $interceptors);
}
return $channel;
}
|
Intercept the methods with Channel
@param Channel|InterceptorChannel $channel An already created Channel or InterceptorChannel object (optional)
@param Interceptor|Interceptor[] $interceptors interceptors to be added
@return InterceptorChannel
|
intercept
|
php
|
grpc/grpc-php
|
src/lib/Interceptor.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/Interceptor.php
|
Apache-2.0
|
public function handle($service)
{
$methodDescriptors = $service->getMethodDescriptors();
$exist_methods = array_intersect_key($this->paths_map, $methodDescriptors);
if (!empty($exist_methods)) {
fwrite(STDERR, "WARNING: " . 'override already registered methods: ' .
implode(', ', array_keys($exist_methods)) . PHP_EOL);
}
$this->paths_map = array_merge($this->paths_map, $methodDescriptors);
return $this->paths_map;
}
|
Add a service to this server
@param Object $service The service to be added
|
handle
|
php
|
grpc/grpc-php
|
src/lib/RpcServer.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/RpcServer.php
|
Apache-2.0
|
public function start($data, array $metadata = [], array $options = [])
{
$message_array = ['message' => $this->_serializeMessage($data)];
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
OP_SEND_MESSAGE => $message_array,
OP_SEND_CLOSE_FROM_CLIENT => true,
]);
}
|
Start the call.
@param mixed $data The data to send
@param array $metadata Metadata to send with the call, if applicable
(optional)
@param array $options An array of options, possible keys:
'flags' => a number (optional)
|
start
|
php
|
grpc/grpc-php
|
src/lib/ServerStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/ServerStreamingCall.php
|
Apache-2.0
|
public function responses()
{
$batch = [OP_RECV_MESSAGE => true];
if ($this->metadata === null) {
$batch[OP_RECV_INITIAL_METADATA] = true;
}
$read_event = $this->call->startBatch($batch);
if ($this->metadata === null) {
$this->metadata = $read_event->metadata;
}
$response = $read_event->message;
while ($response !== null) {
yield $this->_deserializeResponse($response);
$response = $this->call->startBatch([
OP_RECV_MESSAGE => true,
])->message;
}
}
|
@return mixed An iterator of response values
|
responses
|
php
|
grpc/grpc-php
|
src/lib/ServerStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/ServerStreamingCall.php
|
Apache-2.0
|
public function getStatus()
{
$status_event = $this->call->startBatch([
OP_RECV_STATUS_ON_CLIENT => true,
]);
$this->trailing_metadata = $status_event->status->metadata;
return $status_event->status;
}
|
Wait for the server to send the status, and return it.
@return \stdClass The status object, with integer $code, string
$details, and array $metadata members
|
getStatus
|
php
|
grpc/grpc-php
|
src/lib/ServerStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/ServerStreamingCall.php
|
Apache-2.0
|
public function getMetadata()
{
if ($this->metadata === null) {
$event = $this->call->startBatch([OP_RECV_INITIAL_METADATA => true]);
$this->metadata = $event->metadata;
}
return $this->metadata;
}
|
@return mixed The metadata sent by the server
|
getMetadata
|
php
|
grpc/grpc-php
|
src/lib/ServerStreamingCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/ServerStreamingCall.php
|
Apache-2.0
|
public function start($data, array $metadata = [], array $options = [])
{
$message_array = ['message' => $this->_serializeMessage($data)];
if (isset($options['flags'])) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
OP_SEND_MESSAGE => $message_array,
OP_SEND_CLOSE_FROM_CLIENT => true,
]);
}
|
Start the call.
@param mixed $data The data to send
@param array $metadata Metadata to send with the call, if applicable
(optional)
@param array $options An array of options, possible keys:
'flags' => a number (optional)
|
start
|
php
|
grpc/grpc-php
|
src/lib/UnaryCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/UnaryCall.php
|
Apache-2.0
|
public function wait()
{
$batch = [
OP_RECV_MESSAGE => true,
OP_RECV_STATUS_ON_CLIENT => true,
];
if ($this->metadata === null) {
$batch[OP_RECV_INITIAL_METADATA] = true;
}
$event = $this->call->startBatch($batch);
if ($this->metadata === null) {
$this->metadata = $event->metadata;
}
$status = $event->status;
$this->trailing_metadata = $status->metadata;
return [$this->_deserializeResponse($event->message), $status];
}
|
Wait for the server to respond with data and a status.
@return array [response data, status]
|
wait
|
php
|
grpc/grpc-php
|
src/lib/UnaryCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/UnaryCall.php
|
Apache-2.0
|
public function getMetadata()
{
if ($this->metadata === null) {
$event = $this->call->startBatch([OP_RECV_INITIAL_METADATA => true]);
$this->metadata = $event->metadata;
}
return $this->metadata;
}
|
@return mixed The metadata sent by the server
|
getMetadata
|
php
|
grpc/grpc-php
|
src/lib/UnaryCall.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/UnaryCall.php
|
Apache-2.0
|
public function __construct($channel, $interceptor)
{
if (!is_a($channel, 'Grpc\Channel') &&
!is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
throw new \Exception('The channel argument is not a Channel object '.
'or an InterceptorChannel object created by '.
'Interceptor::intercept($channel, Interceptor|Interceptor[] $interceptors)');
}
$this->interceptor = $interceptor;
$this->next = $channel;
}
|
@param Channel|InterceptorChannel $channel An already created Channel
or InterceptorChannel object (optional)
@param Interceptor $interceptor
|
__construct
|
php
|
grpc/grpc-php
|
src/lib/Internal/InterceptorChannel.php
|
https://github.com/grpc/grpc-php/blob/master/src/lib/Internal/InterceptorChannel.php
|
Apache-2.0
|
function json_decode($content, $assoc = false, $depth = 512, $options = 0)
{
return Helpers::decode($content, $assoc, $depth, $options);
}
|
Decodes a JSON string.
@param string $content
@param bool $assoc
@param int $depth
@param int $options
@return object|array
@throws InvalidJsonException
|
json_decode
|
php
|
cloudcreativity/laravel-json-api
|
helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/helpers.php
|
Apache-2.0
|
function http_contains_body($request, $response = null)
{
return $response ?
Helpers::doesResponseHaveBody($request, $response) :
Helpers::doesRequestHaveBody($request);
}
|
Does the HTTP message contain body content?
If only a request is provided, the method will determine if the request contains body.
If a request and response is provided, the method will determine if the response contains
body. Determining this for a response is dependent on the request method, which is why
the request is also required.
@param RequestInterface|Request $request
@param ResponseInterface|Response $response
@return bool
|
http_contains_body
|
php
|
cloudcreativity/laravel-json-api
|
helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/helpers.php
|
Apache-2.0
|
function json_api($apiName = null, $host = null, array $parameters = []) {
if ($apiName) {
return app('json-api')->api($apiName, $host, $parameters);
}
return app('json-api')->requestApiOrDefault($host, $parameters);
}
|
Get a named API, the API handling the inbound request or the default API.
@param string|null $apiName
the API name, or null to get either the API handling the inbound request or the default.
@param string|null $host
the host to use, or null to use the API's configured settings.
@param array $parameters
route parameters to use for the API namespace.
@return Api
@throws RuntimeException
|
json_api
|
php
|
cloudcreativity/laravel-json-api
|
helpers.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/helpers.php
|
Apache-2.0
|
public function __construct(IlluminateContainer $container, ResolverInterface $resolver)
{
$this->container = $container;
$this->resolver = $resolver;
}
|
Container constructor.
@param IlluminateContainer $container
@param ResolverInterface $resolver
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
public function getSchemaByType(string $type): SchemaProviderInterface
{
$resourceType = $this->getResourceType($type);
return $this->getSchemaByResourceType($resourceType);
}
|
Get resource by object type.
@param string $type
@return SchemaProviderInterface
|
getSchemaByType
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
public function getSchemaByResourceType(string $resourceType): SchemaProviderInterface
{
if ($this->hasCreatedSchema($resourceType)) {
return $this->getCreatedSchema($resourceType);
}
if (!$this->resolver->isResourceType($resourceType)) {
throw new RuntimeException("Cannot create a schema because $resourceType is not a valid resource type.");
}
$className = $this->resolver->getSchemaByResourceType($resourceType);
$schema = $this->createSchemaFromClassName($className);
$this->setCreatedSchema($resourceType, $schema);
return $schema;
}
|
Get resource by JSON:API type.
@param string $resourceType
@return SchemaProviderInterface
|
getSchemaByResourceType
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
protected function getResourceType($type)
{
if (!$resourceType = $this->resolver->getResourceType($type)) {
throw new RuntimeException("No JSON API resource type registered for PHP class {$type}.");
}
return $resourceType;
}
|
Get the JSON API resource type for the provided PHP type.
@param $type
@return null|string
|
getResourceType
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
protected function setCreatedSchema($resourceType, SchemaProviderInterface $schema): void
{
$this->createdSchemas[$resourceType] = $schema;
}
|
@param string $resourceType
@param SchemaProviderInterface $schema
@return void
|
setCreatedSchema
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
protected function getCreatedAdapter($resourceType)
{
return $this->createdAdapters[$resourceType];
}
|
@param string $resourceType
@return ResourceAdapterInterface|null
|
getCreatedAdapter
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
protected function setCreatedAdapter($resourceType, ?ResourceAdapterInterface $adapter = null)
{
$this->createdAdapters[$resourceType] = $adapter;
}
|
@param string $resourceType
@param ResourceAdapterInterface|null $adapter
@return void
|
setCreatedAdapter
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
protected function getCreatedValidators($resourceType)
{
return $this->createdValidators[$resourceType];
}
|
@param string $resourceType
@return ValidatorFactoryInterface|null
|
getCreatedValidators
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
protected function setCreatedValidators($resourceType, $validators = null)
{
$this->createdValidators[$resourceType] = $validators;
}
|
@param string $resourceType
@param ValidatorFactoryInterface|null $validators
@return void
|
setCreatedValidators
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
protected function getCreatedAuthorizer($resourceType)
{
return $this->createdAuthorizers[$resourceType];
}
|
@param string $resourceType
@return AuthorizerInterface|null
|
getCreatedAuthorizer
|
php
|
cloudcreativity/laravel-json-api
|
src/Container.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Container.php
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.