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 addShippingAddress(string $full_name, string $address_line_1, string $address_line_2, string $admin_area_2, string $admin_area_1, string $postal_code, string $country_code): \Srmklive\PayPal\Services\PayPal
{
$this->shipping_address = [
'name' => [
'full_name' => $full_name,
],
'address' => [
'address_line_1' => $address_line_1,
'address_line_2' => $address_line_2,
'admin_area_2' => $admin_area_2,
'admin_area_1' => $admin_area_1,
'postal_code' => $postal_code,
'country_code' => $country_code,
],
];
return $this;
}
|
Add shipping address.
@param string $full_name
@param string $address_line_1
@param string $address_line_2
@param string $admin_area_2
@param string $admin_area_1
@param string $postal_code
@param string $country_code
@return \Srmklive\PayPal\Services\PayPal
|
addShippingAddress
|
php
|
srmklive/laravel-paypal
|
src/Traits/PayPalAPI/Subscriptions/Helpers.php
|
https://github.com/srmklive/laravel-paypal/blob/master/src/Traits/PayPalAPI/Subscriptions/Helpers.php
|
MIT
|
public function addTaxes(float $percentage)
{
$this->taxes = [
'percentage' => $percentage,
'inclusive' => false,
];
return $this;
}
|
Add taxes when creating a subscription.
@param float $percentage
@return \Srmklive\PayPal\Services\PayPal
|
addTaxes
|
php
|
srmklive/laravel-paypal
|
src/Traits/PayPalAPI/Subscriptions/Helpers.php
|
https://github.com/srmklive/laravel-paypal/blob/master/src/Traits/PayPalAPI/Subscriptions/Helpers.php
|
MIT
|
public function addCustomId(string $custom_id)
{
$this->custom_id = $custom_id;
return $this;
}
|
Add custom id.
@param string $custom_id
@return \Srmklive\PayPal\Services\PayPal
|
addCustomId
|
php
|
srmklive/laravel-paypal
|
src/Traits/PayPalAPI/Subscriptions/Helpers.php
|
https://github.com/srmklive/laravel-paypal/blob/master/src/Traits/PayPalAPI/Subscriptions/Helpers.php
|
MIT
|
public function getGraph()
{
$vertices = $this->getVertices();
$vertex = \reset($vertices);
\assert($vertex instanceof Vertex);
return $vertex->getGraph();
}
|
get graph instance this edge is attached to
@return Graph
|
getGraph
|
php
|
graphp/graph
|
src/Edge.php
|
https://github.com/graphp/graph/blob/master/src/Edge.php
|
MIT
|
private function __clone()
{
throw new \BadMethodCallException();
}
|
do NOT allow cloning of objects
@throws \BadMethodCallException
@codeCoverageIgnore
|
__clone
|
php
|
graphp/graph
|
src/Edge.php
|
https://github.com/graphp/graph/blob/master/src/Edge.php
|
MIT
|
public function __construct(Vertex $from, Vertex $to, array $attributes = array())
{
if ($from->getGraph() !== $to->getGraph()) {
throw new \InvalidArgumentException('Vertices have to be within the same graph');
}
$this->from = $from;
$this->to = $to;
$this->attributes = $attributes;
$from->getGraph()->addEdge($this);
$from->addEdge($this);
$to->addEdge($this);
}
|
[Internal] Create a new directed Edge from Vertex $from to Vertex $to
@param Vertex $from start/source Vertex
@param Vertex $to end/target Vertex
@param array $attributes
@see Graph::createEdgeDirected() to create directed edges
@see Graph::createEdgeUndirected() to create undirected edges
@internal
|
__construct
|
php
|
graphp/graph
|
src/EdgeDirected.php
|
https://github.com/graphp/graph/blob/master/src/EdgeDirected.php
|
MIT
|
public function getVertexEnd()
{
return $this->to;
}
|
get end/target vertex
@return Vertex
|
getVertexEnd
|
php
|
graphp/graph
|
src/EdgeDirected.php
|
https://github.com/graphp/graph/blob/master/src/EdgeDirected.php
|
MIT
|
public function __construct(Vertex $a, Vertex $b, array $attributes = array())
{
if ($a->getGraph() !== $b->getGraph()) {
throw new \InvalidArgumentException('Vertices have to be within the same graph');
}
$this->a = $a;
$this->b = $b;
$this->attributes = $attributes;
$a->getGraph()->addEdge($this);
$a->addEdge($this);
$b->addEdge($this);
}
|
[Internal] Create a new undirected edge between given vertices
@param Vertex $a
@param Vertex $b
@param array $attributes
@see Graph::createEdgeUndirected() to create undirected edges
@see Graph::createEdgeDirected() to create directed edges
@internal
|
__construct
|
php
|
graphp/graph
|
src/EdgeUndirected.php
|
https://github.com/graphp/graph/blob/master/src/EdgeUndirected.php
|
MIT
|
public function getAttribute($name, $default = null)
{
return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
}
|
get a single attribute with the given $name (or return $default if attribute was not found)
@param string $name
@param mixed $default to return if attribute was not found
@return mixed
|
getAttribute
|
php
|
graphp/graph
|
src/Entity.php
|
https://github.com/graphp/graph/blob/master/src/Entity.php
|
MIT
|
public function setAttribute($name, $value)
{
$this->attributes[$name] = $value;
return $this;
}
|
set a single attribute with the given $name to given $value
@param string $name
@param mixed $value
@return $this chainable
|
setAttribute
|
php
|
graphp/graph
|
src/Entity.php
|
https://github.com/graphp/graph/blob/master/src/Entity.php
|
MIT
|
public function removeAttribute($name)
{
unset($this->attributes[$name]);
return $this;
}
|
Removes a single attribute with the given $name
@param string $name
@return $this chainable
|
removeAttribute
|
php
|
graphp/graph
|
src/Entity.php
|
https://github.com/graphp/graph/blob/master/src/Entity.php
|
MIT
|
public function getAttributes()
{
return $this->attributes;
}
|
get an array of all attributes
@return array
|
getAttributes
|
php
|
graphp/graph
|
src/Entity.php
|
https://github.com/graphp/graph/blob/master/src/Entity.php
|
MIT
|
public function setAttributes(array $attributes)
{
$this->attributes = $attributes + $this->attributes;
return $this;
}
|
set an array of additional attributes
@param array $attributes
@return $this chainable
|
setAttributes
|
php
|
graphp/graph
|
src/Entity.php
|
https://github.com/graphp/graph/blob/master/src/Entity.php
|
MIT
|
public function getVertices()
{
return $this->vertices;
}
|
return list of all vertices added to this graph
@psalm-return list<Vertex>
@return Vertex[]
|
getVertices
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function getEdges()
{
return $this->edges;
}
|
return list of all edges added to this graph
@psalm-return list<Edge>
@return Edge[]
|
getEdges
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function createVertex(array $attributes = array())
{
return new Vertex($this, $attributes);
}
|
create a new Vertex in the Graph
@param array $attributes
@return Vertex
|
createVertex
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function createEdgeUndirected(Vertex $a, Vertex $b, array $attributes = array())
{
if ($a->getGraph() !== $this) {
throw new \InvalidArgumentException('Vertices have to be within this graph');
}
return new EdgeUndirected($a, $b, $attributes);
}
|
Creates a new undirected (bidirectional) edge between the given two vertices.
@param Vertex $a
@param Vertex $b
@param array $attributes
@return EdgeUndirected
@throws \InvalidArgumentException
|
createEdgeUndirected
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function createEdgeDirected(Vertex $source, Vertex $target, array $attributes = array())
{
if ($source->getGraph() !== $this) {
throw new \InvalidArgumentException('Vertices have to be within this graph');
}
return new EdgeDirected($source, $target, $attributes);
}
|
Creates a new directed edge from the given start vertex to given target vertex
@param Vertex $source source vertex
@param Vertex $target target vertex
@param array $attributes
@return EdgeDirected
@throws \InvalidArgumentException
|
createEdgeDirected
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function withoutVertex(Vertex $vertex)
{
return $this->withoutVertices(array($vertex));
}
|
Returns a copy of this graph without the given vertex
If this vertex was not found in this graph, the returned graph will be
identical.
@param Vertex $vertex
@return self
|
withoutVertex
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function withoutVertices(array $vertices)
{
// keep copy of original vertices and edges and temporarily remove all $vertices and their adjacent edges
$originalEdges = $this->edges;
$originalVertices = $this->vertices;
foreach ($vertices as $vertex) {
if (($key = \array_search($vertex, $this->vertices, true)) !== false) {
unset($this->vertices[$key]);
foreach ($vertex->getEdges() as $edge) {
if (($key = \array_search($edge, $this->edges, true)) !== false) {
unset($this->edges[$key]);
}
}
}
}
// no vertices matched => return graph as-is
if (\count($this->vertices) === \count($originalVertices)) {
return $this;
}
// clone graph with vertices/edges temporarily removed, then restore
$clone = clone $this;
$this->edges = $originalEdges;
$this->vertices = $originalVertices;
return $clone;
}
|
Returns a copy of this graph without the given vertices
If any of the given vertices can not be found in this graph, they will
silently be ignored. If neither of the vertices can be found in this graph,
the returned graph will be identical.
@param Vertex[] $vertices
@return self
|
withoutVertices
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function withoutEdge(Edge $edge)
{
return $this->withoutEdges(array($edge));
}
|
Returns a copy of this graph without the given edge
If this edge was not found in this graph, the returned graph will be
identical.
@param Edge $edge
@return self
|
withoutEdge
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function withoutEdges(array $edges)
{
// keep copy of original edges and temporarily remove all $edges
$original = $this->edges;
foreach ($edges as $edge) {
if (($key = \array_search($edge, $this->edges, true)) !== false) {
unset($this->edges[$key]);
}
}
// no edges matched => return graph as-is
if (\count($this->edges) === \count($original)) {
return $this;
}
// clone graph with edges temporarily removed, then restore
$clone = clone $this;
$this->edges = $original;
return $clone;
}
|
Returns a copy of this graph without the given edges
If any of the given edges can not be found in this graph, they will
silently be ignored. If neither of the edges can be found in this graph,
the returned graph will be identical.
@param Edge[] $edges
@return self
|
withoutEdges
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function addVertex(Vertex $vertex)
{
$this->vertices[] = $vertex;
}
|
adds a new Vertex to the Graph (MUST NOT be called manually!)
@param Vertex $vertex instance of the new Vertex
@return void
@internal
@see self::createVertex() instead!
|
addVertex
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function addEdge(Edge $edge)
{
$this->edges []= $edge;
}
|
adds a new Edge to the Graph (MUST NOT be called manually!)
@param Edge $edge instance of the new Edge
@return void
@internal
@see Graph::createEdgeUndirected() instead!
|
addEdge
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function __clone()
{
$vertices = $this->vertices;
$this->vertices = array();
$edges = $this->edges;
$this->edges = array();
$map = array();
foreach ($vertices as $originalVertex) {
\assert($originalVertex instanceof Vertex);
$vertex = new Vertex($this, $originalVertex->getAttributes());
// create map with old vertex hash to new vertex object
$map[\spl_object_hash($originalVertex)] = $vertex;
}
foreach ($edges as $originalEdge) {
\assert($originalEdge instanceof Edge);
// use map to match old vertex hashes to new vertex objects
$vertices = $originalEdge->getVertices();
$v1 = $map[\spl_object_hash($vertices[0])];
$v2 = $map[\spl_object_hash($vertices[1])];
// recreate edge and assign attributes
if ($originalEdge instanceof EdgeUndirected) {
$this->createEdgeUndirected($v1, $v2, $originalEdge->getAttributes());
} else {
$this->createEdgeDirected($v1, $v2, $originalEdge->getAttributes());
}
}
}
|
create new clone/copy of this graph - copy all attributes, vertices and edges
|
__clone
|
php
|
graphp/graph
|
src/Graph.php
|
https://github.com/graphp/graph/blob/master/src/Graph.php
|
MIT
|
public function __construct(Graph $graph, array $attributes = array())
{
$this->graph = $graph;
$this->attributes = $attributes;
$graph->addVertex($this);
}
|
Create a new Vertex
@param Graph $graph graph to be added to
@param array $attributes
@see Graph::createVertex() to create new vertices
|
__construct
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getGraph()
{
return $this->graph;
}
|
get graph this vertex is attached to
@return Graph
|
getGraph
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function addEdge(Edge $edge)
{
$this->edges[] = $edge;
}
|
add the given edge to list of connected edges (MUST NOT be called manually)
@param Edge $edge
@return void
@internal
@see Graph::createEdgeUndirected() instead!
|
addEdge
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function hasEdgeTo(Vertex $vertex)
{
foreach ($this->edges as $edge) {
if ($edge->isConnection($this, $vertex)) {
return true;
}
}
return false;
}
|
check whether this vertex has a direct edge to given $vertex
@param Vertex $vertex
@return bool
@uses Edge::hasVertexTarget()
|
hasEdgeTo
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function hasEdgeFrom(Vertex $vertex)
{
return $vertex->hasEdgeTo($this);
}
|
check whether the given vertex has a direct edge to THIS vertex
@param Vertex $vertex
@return bool
@uses Vertex::hasEdgeTo()
|
hasEdgeFrom
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getEdges()
{
return $this->edges;
}
|
get list of ALL edges attached to this vertex
@psalm-return list<Edge>
@return Edge[]
|
getEdges
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getEdgesOut()
{
$that = $this;
$prev = null;
return \array_values(\array_filter($this->edges, function (Edge $edge) use ($that, &$prev) {
$ret = $edge->hasVertexStart($that);
// skip duplicate directed loop edges
if ($edge === $prev && $edge instanceof EdgeDirected) {
$ret = false;
}
$prev = $edge;
return $ret;
}));
}
|
get list of all outgoing edges attached to this vertex
@psalm-return list<Edge>
@return Edge[]
|
getEdgesOut
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getEdgesIn()
{
$that = $this;
$prev = null;
return \array_values(\array_filter($this->edges, function (Edge $edge) use ($that, &$prev) {
$ret = $edge->hasVertexTarget($that);
// skip duplicate directed loop edges
if ($edge === $prev && $edge instanceof EdgeDirected) {
$ret = false;
}
$prev = $edge;
return $ret;
}));
}
|
get list of all ingoing edges attached to this vertex
@psalm-return list<Edge>
@return Edge[]
|
getEdgesIn
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getEdgesTo(Vertex $vertex)
{
$that = $this;
return \array_values(\array_filter($this->edges, function (Edge $edge) use ($that, $vertex) {
return $edge->isConnection($that, $vertex);
}));
}
|
get list of edges FROM this vertex TO the given vertex
@param Vertex $vertex
@psalm-return list<Edge>
@return Edge[]
@uses Edge::hasVertexTarget()
|
getEdgesTo
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getEdgesFrom(Vertex $vertex)
{
return $vertex->getEdgesTo($this);
}
|
get list of edges FROM the given vertex TO this vertex
@param Vertex $vertex
@psalm-return list<Edge>
@return Edge[]
@uses Vertex::getEdgesTo()
|
getEdgesFrom
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getVerticesEdge()
{
$ret = array();
foreach ($this->edges as $edge) {
if ($edge->hasVertexStart($this)) {
$ret []= $edge->getVertexToFrom($this);
} else {
$ret []= $edge->getVertexFromTo($this);
}
}
return $ret;
}
|
get list of adjacent vertices of this vertex (edge FROM or TO this vertex)
If there are multiple parallel edges between the same Vertex, it will be
returned several times in the resulting list of vertices.
@psalm-return list<Vertex>
@return Vertex[]
@uses Edge::hasVertexStart()
@uses Edge::getVerticesToFrom()
@uses Edge::getVerticesFromTo()
|
getVerticesEdge
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getVerticesEdgeTo()
{
$ret = array();
foreach ($this->getEdgesOut() as $edge) {
$ret []= $edge->getVertexToFrom($this);
}
return $ret;
}
|
get list of all vertices this vertex has an edge to
If there are multiple parallel edges to the same Vertex, it will be
returned several times in the resulting list of vertices.
@psalm-return list<Vertex>
@return Vertex[]
@uses Vertex::getEdgesOut()
@uses Edge::getVerticesToFrom()
|
getVerticesEdgeTo
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public function getVerticesEdgeFrom()
{
$ret = array();
foreach ($this->getEdgesIn() as $edge) {
$ret []= $edge->getVertexFromTo($this);
}
return $ret;
}
|
get list of all vertices that have an edge TO this vertex
If there are multiple parallel edges from the same Vertex, it will be
returned several times in the resulting list of vertices.
@psalm-return list<Vertex>
@return Vertex[]
@uses Vertex::getEdgesIn()
@uses Edge::getVerticesFromTo()
|
getVerticesEdgeFrom
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
private function __clone()
{
throw new \BadMethodCallException();
}
|
do NOT allow cloning of objects
@throws \BadMethodCallException
@codeCoverageIgnore
|
__clone
|
php
|
graphp/graph
|
src/Vertex.php
|
https://github.com/graphp/graph/blob/master/src/Vertex.php
|
MIT
|
public static function factoryFromEdges(array $edges, Vertex $startVertex)
{
$vertices = array($startVertex);
$vertexCurrent = $startVertex;
foreach ($edges as $edge) {
$vertexCurrent = $edge->getVertexToFrom($vertexCurrent);
$vertices []= $vertexCurrent;
}
return new self($vertices, \array_values($edges));
}
|
construct new walk from given start vertex and given array of edges
@param Edge[] $edges
@param Vertex $startVertex
@return Walk
|
factoryFromEdges
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
public static function factoryFromVertices(array $vertices, $orderBy = null, $desc = false)
{
$edges = array();
$last = NULL;
foreach ($vertices as $vertex) {
// skip first vertex as last is unknown
if ($last !== NULL) {
// pick edge between last vertex and this vertex
\assert($last instanceof Vertex);
$edges[] = self::pickEdge($last->getEdgesTo($vertex), $orderBy, $desc);
}
$last = $vertex;
}
if ($last === NULL) {
throw new \UnderflowException('No vertices given');
}
return new self(\array_values($vertices), $edges);
}
|
create new walk instance between given array of Vertex instances
@param Vertex[] $vertices
@param null|string|callable(Edge):number $orderBy
@param bool $desc
@return Walk
@throws \UnderflowException if no vertices were given
@see self::factoryCycleFromVertices() for parameters $orderBy and $desc
|
factoryFromVertices
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
public static function factoryCycleFromVertices(array $vertices, $orderBy = null, $desc = false)
{
$cycle = self::factoryFromVertices($vertices, $orderBy, $desc);
if (!$cycle->getEdges()) {
throw new \InvalidArgumentException('Cycle with no edges can not exist');
}
if (\reset($vertices) !== \end($vertices)) {
throw new \InvalidArgumentException('Cycle has to start and end at the same vertex');
}
return $cycle;
}
|
create new cycle instance with edges between given vertices
@param Vertex[] $vertices
@param null|string|callable(Edge):number $orderBy
@param bool $desc
@return Walk
@throws \UnderflowException if no vertices were given
@throws \InvalidArgumentException if vertices do not form a valid cycle
@see self::factoryCycleFromVertices() for parameters $orderBy and $desc
@uses self::factoryFromVertices()
|
factoryCycleFromVertices
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
public static function factoryCycleFromEdges(array $edges, Vertex $startVertex)
{
$cycle = self::factoryFromEdges($edges, $startVertex);
// ensure this walk is actually a cycle by checking start = end
$vertices = $cycle->getVertices();
if (\end($vertices) !== $startVertex) {
throw new \InvalidArgumentException('The given array of edges does not represent a cycle');
}
return $cycle;
}
|
create new cycle instance with vertices connected by given edges
@param Edge[] $edges
@param Vertex $startVertex
@return Walk
@throws \InvalidArgumentException if the given array of edges does not represent a valid cycle
@uses self::factoryFromEdges()
|
factoryCycleFromEdges
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
private static function pickEdge(array $edges, $orderBy, $desc)
{
if (!$edges) {
throw new \UnderflowException('No edges between two vertices found');
}
if ($orderBy === null) {
return \reset($edges);
}
if (\is_string($orderBy)) {
$orderBy = function (Edge $edge) use ($orderBy) {
return $edge->getAttribute($orderBy);
};
}
$ret = NULL;
$best = NULL;
foreach ($edges as $edge) {
$now = $orderBy($edge);
if ($ret === NULL || ($desc && $now > $best) || (!$desc && $now < $best)) {
$ret = $edge;
$best = $now;
}
}
return $ret;
}
|
@param Edge[] $edges
@param null|string|callable(Edge):number $orderBy
@param bool $desc
@return Edge
@throws \UnderflowException
|
pickEdge
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
protected function __construct(array $vertices, array $edges)
{
$this->vertices = $vertices;
$this->edges = $edges;
}
|
@psalm-param list<Vertex> $vertices
@psalm-param list<Edge> $edges
@param Vertex[] $vertices
@param Edge[] $edges
|
__construct
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
public function getGraph()
{
$vertex = \reset($this->vertices);
\assert($vertex instanceof Vertex);
return $vertex->getGraph();
}
|
return original graph
@return Graph
@uses self::getVertices()
@uses Vertices::getVertexFirst()
@uses Vertex::getGraph()
|
getGraph
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
public function getEdges()
{
return $this->edges;
}
|
return list of all edges of walk (in sequence visited in walk, may contain duplicates)
@psalm-return list<Edge>
@return Edge[]
|
getEdges
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
public function getVertices()
{
return $this->vertices;
}
|
return list of all vertices of walk (in sequence visited in walk, may contain duplicates)
If you need to return the source vertex (first vertex of walk), you can
use something like this:
```php
$vertices = $walk->getVertices();
$firstVertex = \reset($vertices);
```
If you need to return the target/destination vertex (last vertex of walk),
you can use something like this:
```php
$vertices = $walk->getVertices();
$lastVertex = \end($vertices);
```
@psalm-return list<Vertex>
@return Vertex[]
|
getVertices
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
public function getAlternatingSequence()
{
$ret = array();
for ($i = 0, $l = \count($this->edges); $i < $l; ++$i) {
$ret []= $this->vertices[$i];
$ret []= $this->edges[$i];
}
$ret[] = $this->vertices[$i];
return $ret;
}
|
get alternating sequence of vertex, edge, vertex, edge, ..., vertex
@psalm-return list<Vertex|Edge>
@return array<int,Vertex|Edge>
|
getAlternatingSequence
|
php
|
graphp/graph
|
src/Walk.php
|
https://github.com/graphp/graph/blob/master/src/Walk.php
|
MIT
|
public static function create_hash($password)
{
// format: algorithm:iterations:outputSize:salt:pbkdf2output
if (!\is_string($password)) {
throw new InvalidArgumentException(
"create_hash(): Expected a string"
);
}
if (\function_exists('random_bytes')) {
try {
$salt_raw = \random_bytes(self::PBKDF2_SALT_BYTES);
} catch (Error $e) {
$salt_raw = false;
} catch (Exception $e) {
$salt_raw = false;
} catch (TypeError $e) {
$salt_raw = false;
}
} else {
$salt_raw = @\mcrypt_create_iv(self::PBKDF2_SALT_BYTES, MCRYPT_DEV_URANDOM);
}
if ($salt_raw === false) {
throw new CannotPerformOperationException(
"Random number generator failed. Not safe to proceed."
);
}
$PBKDF2_Output = self::pbkdf2(
self::PBKDF2_HASH_ALGORITHM,
$password,
$salt_raw,
self::PBKDF2_ITERATIONS,
self::PBKDF2_OUTPUT_BYTES,
true
);
return self::PBKDF2_HASH_ALGORITHM .
":" .
self::PBKDF2_ITERATIONS .
":" .
self::PBKDF2_OUTPUT_BYTES .
":" .
\base64_encode($salt_raw) .
":" .
\base64_encode($PBKDF2_Output);
}
|
Hash a password with PBKDF2
@param string $password
@return string
|
create_hash
|
php
|
defuse/password-hashing
|
PasswordStorage.php
|
https://github.com/defuse/password-hashing/blob/master/PasswordStorage.php
|
BSD-2-Clause
|
public static function verify_password($password, $hash)
{
if (!\is_string($password) || !\is_string($hash)) {
throw new InvalidArgumentException(
"verify_password(): Expected two strings"
);
}
$params = \explode(":", $hash);
if (\count($params) !== self::HASH_SECTIONS) {
throw new InvalidHashException(
"Fields are missing from the password hash."
);
}
$pbkdf2 = \base64_decode($params[self::HASH_PBKDF2_INDEX], true);
if ($pbkdf2 === false) {
throw new InvalidHashException(
"Base64 decoding of pbkdf2 output failed."
);
}
$salt_raw = \base64_decode($params[self::HASH_SALT_INDEX], true);
if ($salt_raw === false) {
throw new InvalidHashException(
"Base64 decoding of salt failed."
);
}
$storedOutputSize = (int) $params[self::HASH_SIZE_INDEX];
if (self::ourStrlen($pbkdf2) !== $storedOutputSize) {
throw new InvalidHashException(
"PBKDF2 output length doesn't match stored output length."
);
}
$iterations = (int) $params[self::HASH_ITERATION_INDEX];
if ($iterations < 1) {
throw new InvalidHashException(
"Invalid number of iterations. Must be >= 1."
);
}
return self::slow_equals(
$pbkdf2,
self::pbkdf2(
$params[self::HASH_ALGORITHM_INDEX],
$password,
$salt_raw,
$iterations,
self::ourStrlen($pbkdf2),
true
)
);
}
|
Verify that a password matches the stored hash
@param string $password
@param string $hash
@return bool
|
verify_password
|
php
|
defuse/password-hashing
|
PasswordStorage.php
|
https://github.com/defuse/password-hashing/blob/master/PasswordStorage.php
|
BSD-2-Clause
|
public static function slow_equals($a, $b)
{
if (!\is_string($a) || !\is_string($b)) {
throw new InvalidArgumentException(
"slow_equals(): expected two strings"
);
}
if (\function_exists('hash_equals')) {
return \hash_equals($a, $b);
}
// PHP < 5.6 polyfill:
$diff = self::ourStrlen($a) ^ self::ourStrlen($b);
for($i = 0; $i < self::ourStrlen($a) && $i < self::ourStrlen($b); $i++) {
$diff |= \ord($a[$i]) ^ \ord($b[$i]);
}
return $diff === 0;
}
|
Compares two strings $a and $b in length-constant time.
@param string $a
@param string $b
@return bool
|
slow_equals
|
php
|
defuse/password-hashing
|
PasswordStorage.php
|
https://github.com/defuse/password-hashing/blob/master/PasswordStorage.php
|
BSD-2-Clause
|
private static function ourStrlen($str)
{
static $exists = null;
if ($exists === null) {
$exists = \function_exists('mb_strlen');
}
if (!\is_string($str)) {
throw new InvalidArgumentException(
"ourStrlen() expects a string"
);
}
if ($exists) {
$length = \mb_strlen($str, '8bit');
if ($length === false) {
throw new CannotPerformOperationException();
}
return $length;
} else {
return \strlen($str);
}
}
|
Calculate the length of a string
@param string $str
@return int
|
ourStrlen
|
php
|
defuse/password-hashing
|
PasswordStorage.php
|
https://github.com/defuse/password-hashing/blob/master/PasswordStorage.php
|
BSD-2-Clause
|
private static function ourSubstr($str, $start, $length = null)
{
static $exists = null;
if ($exists === null) {
$exists = \function_exists('mb_substr');
}
// Type validation:
if (!\is_string($str)) {
throw new InvalidArgumentException(
"ourSubstr() expects a string"
);
}
if ($exists) {
// mb_substr($str, 0, NULL, '8bit') returns an empty string on PHP
// 5.3, so we have to find the length ourselves.
if (!isset($length)) {
if ($start >= 0) {
$length = self::ourStrlen($str) - $start;
} else {
$length = -$start;
}
}
return \mb_substr($str, $start, $length, '8bit');
}
// Unlike mb_substr(), substr() doesn't accept NULL for length
if (isset($length)) {
return \substr($str, $start, $length);
} else {
return \substr($str, $start);
}
}
|
Substring
@param string $str
@param int $start
@param int $length
@return string
|
ourSubstr
|
php
|
defuse/password-hashing
|
PasswordStorage.php
|
https://github.com/defuse/password-hashing/blob/master/PasswordStorage.php
|
BSD-2-Clause
|
public static function color($color = null, $style = null, $background = null) // {{{
{
$colors = &$GLOBALS['_CONSOLE_COLOR_CODES'];
if (is_array($color)) {
$style = @$color['style'];
$background = @$color['background'];
$color = @$color['color'];
}
if ($color == 'reset') {
return "\033[0m";
}
$code = array();
if (isset($color)) {
$code[] = $colors['color'][$color];
}
if (isset($style)) {
$code[] = $colors['style'][$style];
}
if (isset($background)) {
$code[] = $colors['background'][$background];
}
if (empty($code)) {
$code[] = 0;
}
$code = implode(';', $code);
return "\033[{$code}m";
}
|
Returns an ANSI-Controlcode
Takes 1 to 3 Arguments: either 1 to 3 strings containing the name of the
FG Color, style and BG color, or one array with the indices color, style
or background.
@param mixed $color Optional.
Either a string with the name of the foreground
color, or an array with the indices 'color',
'style', 'background' and corresponding names as
values.
@param string $style Optional name of the style
@param string $background Optional name of the background color
@access public
@return string
|
color
|
php
|
tombenner/wp-mvc
|
core/console/color.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/color.php
|
MIT
|
public static function fgcolor($name)
{
$colors = &$GLOBALS['_CONSOLE_COLOR_CODES'];
return "\033[".$colors['color'][$name].'m';
}
|
Returns a FG color controlcode
@param string $name Name of controlcode
@access public
@return string
|
fgcolor
|
php
|
tombenner/wp-mvc
|
core/console/color.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/color.php
|
MIT
|
public static function style($name)
{
$colors = &$GLOBALS['_CONSOLE_COLOR_CODES'];
return "\033[".$colors['style'][$name].'m';
}
|
Returns a style controlcode
@param string $name Name of controlcode
@access public
@return string
|
style
|
php
|
tombenner/wp-mvc
|
core/console/color.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/color.php
|
MIT
|
public static function bgcolor($name)
{
$colors = &$GLOBALS['_CONSOLE_COLOR_CODES'];
return "\033[".$colors['background'][$name].'m';
}
|
Returns a BG color controlcode
@param string $name Name of controlcode
@access public
@return string
|
bgcolor
|
php
|
tombenner/wp-mvc
|
core/console/color.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/color.php
|
MIT
|
public static function convert($string, $colored = true)
{
static $conversions = array ( // static so the array doesn't get built
// everytime
// %y - yellow, and so on... {{{
'%y' => array('color' => 'yellow'),
'%g' => array('color' => 'green' ),
'%b' => array('color' => 'blue' ),
'%r' => array('color' => 'red' ),
'%p' => array('color' => 'purple'),
'%m' => array('color' => 'purple'),
'%c' => array('color' => 'cyan' ),
'%w' => array('color' => 'grey' ),
'%k' => array('color' => 'black' ),
'%n' => array('color' => 'reset' ),
'%Y' => array('color' => 'yellow', 'style' => 'light'),
'%G' => array('color' => 'green', 'style' => 'light'),
'%B' => array('color' => 'blue', 'style' => 'light'),
'%R' => array('color' => 'red', 'style' => 'light'),
'%P' => array('color' => 'purple', 'style' => 'light'),
'%M' => array('color' => 'purple', 'style' => 'light'),
'%C' => array('color' => 'cyan', 'style' => 'light'),
'%W' => array('color' => 'grey', 'style' => 'light'),
'%K' => array('color' => 'black', 'style' => 'light'),
'%N' => array('color' => 'reset', 'style' => 'light'),
'%3' => array('background' => 'yellow'),
'%2' => array('background' => 'green' ),
'%4' => array('background' => 'blue' ),
'%1' => array('background' => 'red' ),
'%5' => array('background' => 'purple'),
'%6' => array('background' => 'cyan' ),
'%7' => array('background' => 'grey' ),
'%0' => array('background' => 'black' ),
// Don't use this, I can't stand flashing text
'%F' => array('style' => 'blink'),
'%U' => array('style' => 'underline'),
'%8' => array('style' => 'inverse'),
'%9' => array('style' => 'bold'),
'%_' => array('style' => 'bold')
// }}}
);
if ($colored) {
$string = str_replace('%%', '% ', $string);
foreach ($conversions as $key => $value) {
$string = str_replace($key, Console_Color::color($value),
$string);
}
$string = str_replace('% ', '%', $string);
} else {
$string = preg_replace('/%((%)|.)/', '$2', $string);
}
return $string;
}
|
Converts colorcodes in the format %y (for yellow) into ansi-control
codes. The conversion table is: ('bold' meaning 'light' on some
terminals). It's almost the same conversion table irssi uses.
<pre>
text text background
------------------------------------------------
%k %K %0 black dark grey black
%r %R %1 red bold red red
%g %G %2 green bold green green
%y %Y %3 yellow bold yellow yellow
%b %B %4 blue bold blue blue
%m %M %5 magenta bold magenta magenta
%p %P magenta (think: purple)
%c %C %6 cyan bold cyan cyan
%w %W %7 white bold white white
%F Blinking, Flashing
%U Underline
%8 Reverse
%_,%9 Bold
%n Resets the color
%% A single %
</pre>
First param is the string to convert, second is an optional flag if
colors should be used. It defaults to true, if set to false, the
colorcodes will just be removed (And %% will be transformed into %)
@param string $string String to convert
@param bool $colored Should the string be colored?
@access public
@return string
|
convert
|
php
|
tombenner/wp-mvc
|
core/console/color.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/color.php
|
MIT
|
public static function escape($string)
{
return str_replace('%', '%%', $string);
}
|
Escapes % so they don't get interpreted as color codes
@param string $string String to escape
@access public
@return string
|
escape
|
php
|
tombenner/wp-mvc
|
core/console/color.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/color.php
|
MIT
|
public static function strip($string)
{
return preg_replace('/\033\[[\d;]+m/', '', $string);
}
|
Strips ANSI color codes from a string
@param string $string String to strip
@acess public
@return string
|
strip
|
php
|
tombenner/wp-mvc
|
core/console/color.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/color.php
|
MIT
|
function Console_ProgressBar($formatstring, $bar, $prefill, $width,
$target_num, $options = array())
{
$this->reset($formatstring, $bar, $prefill, $width, $target_num,
$options);
}
|
Constructor, sets format and size
See the reset() method for documentation.
@param string The format string
@param string The string filling the progress bar
@param string The string filling empty space in the bar
@param int The width of the display
@param float The target number for the bar
@param array Options for the progress bar
@see reset
|
Console_ProgressBar
|
php
|
tombenner/wp-mvc
|
core/console/progress_bar.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/progress_bar.php
|
MIT
|
function update($current)
{
$time = $this->_fetchTime();
$this->_addDatapoint($current, $time);
if ($this->_first) {
if ($this->_options['ansi_terminal']) {
echo "\x1b[s"; // save cursor position
}
$this->_first = false;
$this->_start_time = $this->_fetchTime();
$this->display($current);
return;
}
if ($time - $this->_last_update_time <
$this->_options['min_draw_interval'] and $current != $this->_target_num) {
return;
}
$this->erase();
$this->display($current);
$this->_last_update_time = $time;
}
|
Updates the bar with new progress information
@param int current position of the progress counter
@return bool
|
update
|
php
|
tombenner/wp-mvc
|
core/console/progress_bar.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/progress_bar.php
|
MIT
|
function display($current)
{
$percent = $current / $this->_target_num;
$filled = round($percent * $this->_blen);
$visbar = substr($this->_bar, $this->_blen - $filled, $this->_blen);
$elapsed = $this->_formatSeconds(
$this->_fetchTime() - $this->_start_time
);
$estimate = $this->_formatSeconds($this->_generateEstimate());
$this->_rlen = printf($this->_skeleton,
$visbar, $current, $this->_target_num, $percent * 100, $elapsed,
$estimate
);
// fix for php-versions where printf doesn't return anything
if (is_null($this->_rlen)) {
$this->_rlen = $this->_tlen;
// fix for php versions between 4.3.7 and 5.x.y(?)
} elseif ($this->_rlen < $this->_tlen) {
echo str_repeat(' ', $this->_tlen - $this->_rlen);
$this->_rlen = $this->_tlen;
}
return true;
}
|
Prints the bar. Usually, you don't need this method, just use update()
which handles erasing the previously printed bar also. If you use a
custom function (for whatever reason) to erase the bar, use this method.
@param int current position of the progress counter
@return bool
|
display
|
php
|
tombenner/wp-mvc
|
core/console/progress_bar.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/progress_bar.php
|
MIT
|
function erase($clear = false)
{
if ($this->_options['ansi_terminal'] and !$clear) {
if ($this->_options['ansi_clear']) {
echo "\x1b[2K\x1b[u"; // restore cursor position
} else {
echo "\x1b[u"; // restore cursor position
}
} elseif (!$clear) {
echo str_repeat(chr(0x08), $this->_rlen);
} else {
echo str_repeat(chr(0x08), $this->_rlen),
str_repeat(chr(0x20), $this->_rlen),
str_repeat(chr(0x08), $this->_rlen);
}
}
|
Erases a previously printed bar.
@param bool if the bar should be cleared in addition to resetting the
cursor position
@return bool
|
erase
|
php
|
tombenner/wp-mvc
|
core/console/progress_bar.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/progress_bar.php
|
MIT
|
function _formatSeconds($seconds)
{
$hou = floor($seconds/3600);
$min = floor(($seconds - $hou * 3600) / 60);
$sec = $seconds - $hou * 3600 - $min * 60;
if ($hou == 0) {
if (version_compare(PHP_VERSION, '4.3.7', 'ge')) {
$format = '%2$02d:%3$05.2f';
} else {
$format = '%2$02d:%3$02.2f';
}
} elseif ($hou < 100) {
$format = '%02d:%02d:%02d';
} else {
$format = '%05d:%02d';
}
return sprintf($format, $hou, $min, $sec);
}
|
Returns a string containing the formatted number of seconds
@param float The number of seconds
@return string
|
_formatSeconds
|
php
|
tombenner/wp-mvc
|
core/console/progress_bar.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/progress_bar.php
|
MIT
|
function __construct($align = CONSOLE_TABLE_ALIGN_LEFT,
$border = CONSOLE_TABLE_BORDER_ASCII, $padding = 1,
$charset = null, $color = false)
{
$this->_defaultAlign = $align;
$this->_border = $border;
$this->_padding = $padding;
$this->_ansiColor = $color;
if ($this->_ansiColor) {
include_once('color.php');
}
if (!empty($charset)) {
$this->setCharset($charset);
}
}
|
Constructor.
@param integer $align Default alignment. One of
CONSOLE_TABLE_ALIGN_LEFT,
CONSOLE_TABLE_ALIGN_CENTER or
CONSOLE_TABLE_ALIGN_RIGHT.
@param string $border The character used for table borders or
CONSOLE_TABLE_BORDER_ASCII.
@param integer $padding How many spaces to use to pad the table.
@param string $charset A charset supported by the mbstring PHP
extension.
@param boolean $color Whether the data contains ansi color codes.
|
__construct
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function fromArray($headers, $data, $returnObject = false)
{
if (!is_array($headers) || !is_array($data)) {
return false;
}
$table = new Console_Table();
$table->setHeaders($headers);
foreach ($data as $row) {
$table->addRow($row);
}
return $returnObject ? $table : $table->getTable();
}
|
Converts an array to a table.
@param array $headers Headers for the table.
@param array $data A two dimensional array with the table
data.
@param boolean $returnObject Whether to return the Console_Table object
instead of the rendered table.
@static
@return Console_Table|string A Console_Table object or the generated
table.
|
fromArray
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function addFilter($col, &$callback)
{
$this->_filters[] = array($col, &$callback);
}
|
Adds a filter to a column.
Filters are standard PHP callbacks which are run on the data before
table generation is performed. Filters are applied in the order they
are added. The callback function must accept a single argument, which
is a single table cell.
@param integer $col Column to apply filter to.
@param mixed &$callback PHP callback to apply.
@return void
|
addFilter
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function setCharset($charset)
{
$locale = setlocale(LC_CTYPE, 0);
setlocale(LC_CTYPE, 'en_US');
$this->_charset = strtolower($charset);
setlocale(LC_CTYPE, $locale);
}
|
Sets the charset of the provided table data.
@param string $charset A charset supported by the mbstring PHP
extension.
@return void
|
setCharset
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function setAlign($col_id, $align = CONSOLE_TABLE_ALIGN_LEFT)
{
switch ($align) {
case CONSOLE_TABLE_ALIGN_CENTER:
$pad = STR_PAD_BOTH;
break;
case CONSOLE_TABLE_ALIGN_RIGHT:
$pad = STR_PAD_LEFT;
break;
default:
$pad = STR_PAD_RIGHT;
break;
}
$this->_col_align[$col_id] = $pad;
}
|
Sets the alignment for the columns.
@param integer $col_id The column number.
@param integer $align Alignment to set for this column. One of
CONSOLE_TABLE_ALIGN_LEFT
CONSOLE_TABLE_ALIGN_CENTER
CONSOLE_TABLE_ALIGN_RIGHT.
@return void
|
setAlign
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function calculateTotalsFor($cols)
{
$this->_calculateTotals = $cols;
}
|
Specifies which columns are to have totals calculated for them and
added as a new row at the bottom.
@param array $cols Array of column numbers (starting with 0).
@return void
|
calculateTotalsFor
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function setHeaders($headers)
{
$this->_headers = array(array_values($headers));
$this->_updateRowsCols($headers);
}
|
Sets the headers for the columns.
@param array $headers The column headers.
@return void
|
setHeaders
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function addRow($row, $append = true)
{
if ($append) {
$this->_data[] = array_values($row);
} else {
array_unshift($this->_data, array_values($row));
}
$this->_updateRowsCols($row);
}
|
Adds a row to the table.
@param array $row The row data to add.
@param boolean $append Whether to append or prepend the row.
@return void
|
addRow
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function insertRow($row, $row_id = 0)
{
array_splice($this->_data, $row_id, 0, array($row));
$this->_updateRowsCols($row);
}
|
Inserts a row after a given row number in the table.
If $row_id is not given it will prepend the row.
@param array $row The data to insert.
@param integer $row_id Row number to insert before.
@return void
|
insertRow
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function addCol($col_data, $col_id = 0, $row_id = 0)
{
foreach ($col_data as $col_cell) {
$this->_data[$row_id++][$col_id] = $col_cell;
}
$this->_updateRowsCols();
$this->_max_cols = max($this->_max_cols, $col_id + 1);
}
|
Adds a column to the table.
@param array $col_data The data of the column.
@param integer $col_id The column index to populate.
@param integer $row_id If starting row is not zero, specify it here.
@return void
|
addCol
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function addData($data, $col_id = 0, $row_id = 0)
{
foreach ($data as $row) {
if ($row === CONSOLE_TABLE_HORIZONTAL_RULE) {
$this->_data[$row_id] = CONSOLE_TABLE_HORIZONTAL_RULE;
$row_id++;
continue;
}
$starting_col = $col_id;
foreach ($row as $cell) {
$this->_data[$row_id][$starting_col++] = $cell;
}
$this->_updateRowsCols();
$this->_max_cols = max($this->_max_cols, $starting_col);
$row_id++;
}
}
|
Adds data to the table.
@param array $data A two dimensional array with the table data.
@param integer $col_id Starting column number.
@param integer $row_id Starting row number.
@return void
|
addData
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function addSeparator()
{
$this->_data[] = CONSOLE_TABLE_HORIZONTAL_RULE;
}
|
Adds a horizontal seperator to the table.
@return void
|
addSeparator
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function getTable()
{
$this->_applyFilters();
$this->_calculateTotals();
$this->_validateTable();
return $this->_buildTable();
}
|
Returns the generated table.
@return string The generated table.
|
getTable
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _calculateTotals()
{
if (empty($this->_calculateTotals)) {
return;
}
$this->addSeparator();
$totals = array();
foreach ($this->_data as $row) {
if (is_array($row)) {
foreach ($this->_calculateTotals as $columnID) {
$totals[$columnID] += $row[$columnID];
}
}
}
$this->_data[] = $totals;
$this->_updateRowsCols();
}
|
Calculates totals for columns.
@return void
|
_calculateTotals
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _applyFilters()
{
if (empty($this->_filters)) {
return;
}
foreach ($this->_filters as $filter) {
$column = $filter[0];
$callback = $filter[1];
foreach ($this->_data as $row_id => $row_data) {
if ($row_data !== CONSOLE_TABLE_HORIZONTAL_RULE) {
$this->_data[$row_id][$column] =
call_user_func($callback, $row_data[$column]);
}
}
}
}
|
Applies any column filters to the data.
@return void
|
_applyFilters
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _validateTable()
{
if (!empty($this->_headers)) {
$this->_calculateRowHeight(-1, $this->_headers[0]);
}
for ($i = 0; $i < $this->_max_rows; $i++) {
for ($j = 0; $j < $this->_max_cols; $j++) {
if (!isset($this->_data[$i][$j]) &&
(!isset($this->_data[$i]) ||
$this->_data[$i] !== CONSOLE_TABLE_HORIZONTAL_RULE)) {
$this->_data[$i][$j] = '';
}
}
$this->_calculateRowHeight($i, $this->_data[$i]);
if ($this->_data[$i] !== CONSOLE_TABLE_HORIZONTAL_RULE) {
ksort($this->_data[$i]);
}
}
$this->_splitMultilineRows();
// Update cell lengths.
for ($i = 0; $i < count($this->_headers); $i++) {
$this->_calculateCellLengths($this->_headers[$i]);
}
for ($i = 0; $i < $this->_max_rows; $i++) {
$this->_calculateCellLengths($this->_data[$i]);
}
ksort($this->_data);
}
|
Ensures that column and row counts are correct.
@return void
|
_validateTable
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _splitMultilineRows()
{
ksort($this->_data);
$sections = array(&$this->_headers, &$this->_data);
$max_rows = array(count($this->_headers), $this->_max_rows);
$row_height_offset = array(-1, 0);
for ($s = 0; $s <= 1; $s++) {
$inserted = 0;
$new_data = $sections[$s];
for ($i = 0; $i < $max_rows[$s]; $i++) {
// Process only rows that have many lines.
$height = $this->_row_heights[$i + $row_height_offset[$s]];
if ($height > 1) {
// Split column data into one-liners.
$split = array();
for ($j = 0; $j < $this->_max_cols; $j++) {
$split[$j] = preg_split('/\r?\n|\r/',
$sections[$s][$i][$j]);
}
$new_rows = array();
// Construct new 'virtual' rows - insert empty strings for
// columns that have less lines that the highest one.
for ($i2 = 0; $i2 < $height; $i2++) {
for ($j = 0; $j < $this->_max_cols; $j++) {
$new_rows[$i2][$j] = !isset($split[$j][$i2])
? ''
: $split[$j][$i2];
}
}
// Replace current row with smaller rows. $inserted is
// used to take account of bigger array because of already
// inserted rows.
array_splice($new_data, $i + $inserted, 1, $new_rows);
$inserted += count($new_rows) - 1;
}
}
// Has the data been modified?
if ($inserted > 0) {
$sections[$s] = $new_data;
$this->_updateRowsCols();
}
}
}
|
Splits multiline rows into many smaller one-line rows.
@return void
|
_splitMultilineRows
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _buildTable()
{
if (!count($this->_data)) {
return '';
}
$rule = $this->_border == CONSOLE_TABLE_BORDER_ASCII
? '|'
: $this->_border;
$separator = $this->_getSeparator();
$return = array();
for ($i = 0; $i < count($this->_data); $i++) {
for ($j = 0; $j < count($this->_data[$i]); $j++) {
if ($this->_data[$i] !== CONSOLE_TABLE_HORIZONTAL_RULE &&
$this->_strlen($this->_data[$i][$j]) <
$this->_cell_lengths[$j]) {
$this->_data[$i][$j] = $this->_strpad($this->_data[$i][$j],
$this->_cell_lengths[$j],
' ',
$this->_col_align[$j]);
}
}
if ($this->_data[$i] !== CONSOLE_TABLE_HORIZONTAL_RULE) {
$row_begin = $rule . str_repeat(' ', $this->_padding);
$row_end = str_repeat(' ', $this->_padding) . $rule;
$implode_char = str_repeat(' ', $this->_padding) . $rule
. str_repeat(' ', $this->_padding);
$return[] = $row_begin
. implode($implode_char, $this->_data[$i]) . $row_end;
} elseif (!empty($separator)) {
$return[] = $separator;
}
}
$return = implode("\r\n", $return);
if (!empty($separator)) {
$return = $separator . "\r\n" . $return . "\r\n" . $separator;
}
$return .= "\r\n";
if (!empty($this->_headers)) {
$return = $this->_getHeaderLine() . "\r\n" . $return;
}
return $return;
}
|
Builds the table.
@return string The generated table string.
|
_buildTable
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _getSeparator()
{
if (!$this->_border) {
return;
}
if ($this->_border == CONSOLE_TABLE_BORDER_ASCII) {
$rule = '-';
$sect = '+';
} else {
$rule = $sect = $this->_border;
}
$return = array();
foreach ($this->_cell_lengths as $cl) {
$return[] = str_repeat($rule, $cl);
}
$row_begin = $sect . str_repeat($rule, $this->_padding);
$row_end = str_repeat($rule, $this->_padding) . $sect;
$implode_char = str_repeat($rule, $this->_padding) . $sect
. str_repeat($rule, $this->_padding);
return $row_begin . implode($implode_char, $return) . $row_end;
}
|
Creates a horizontal separator for header separation and table
start/end etc.
@return string The horizontal separator.
|
_getSeparator
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _getHeaderLine()
{
// Make sure column count is correct
for ($j = 0; $j < count($this->_headers); $j++) {
for ($i = 0; $i < $this->_max_cols; $i++) {
if (!isset($this->_headers[$j][$i])) {
$this->_headers[$j][$i] = '';
}
}
}
for ($j = 0; $j < count($this->_headers); $j++) {
for ($i = 0; $i < count($this->_headers[$j]); $i++) {
if ($this->_strlen($this->_headers[$j][$i]) <
$this->_cell_lengths[$i]) {
$this->_headers[$j][$i] =
$this->_strpad($this->_headers[$j][$i],
$this->_cell_lengths[$i],
' ',
$this->_col_align[$i]);
}
}
}
$rule = $this->_border == CONSOLE_TABLE_BORDER_ASCII
? '|'
: $this->_border;
$row_begin = $rule . str_repeat(' ', $this->_padding);
$row_end = str_repeat(' ', $this->_padding) . $rule;
$implode_char = str_repeat(' ', $this->_padding) . $rule
. str_repeat(' ', $this->_padding);
$separator = $this->_getSeparator();
if (!empty($separator)) {
$return[] = $separator;
}
for ($j = 0; $j < count($this->_headers); $j++) {
$return[] = $row_begin
. implode($implode_char, $this->_headers[$j]) . $row_end;
}
return implode("\r\n", $return);
}
|
Returns the header line for the table.
@return string The header line of the table.
|
_getHeaderLine
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _updateRowsCols($rowdata = null)
{
// Update maximum columns.
$this->_max_cols = max($this->_max_cols, count($rowdata));
// Update maximum rows.
ksort($this->_data);
$keys = array_keys($this->_data);
$this->_max_rows = end($keys) + 1;
switch ($this->_defaultAlign) {
case CONSOLE_TABLE_ALIGN_CENTER:
$pad = STR_PAD_BOTH;
break;
case CONSOLE_TABLE_ALIGN_RIGHT:
$pad = STR_PAD_LEFT;
break;
default:
$pad = STR_PAD_RIGHT;
break;
}
// Set default column alignments
for ($i = count($this->_col_align); $i < $this->_max_cols; $i++) {
$this->_col_align[$i] = $pad;
}
}
|
Updates values for maximum columns and rows.
@param array $rowdata Data array of a single row.
@return void
|
_updateRowsCols
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _calculateCellLengths($row)
{
for ($i = 0; $i < count($row); $i++) {
if (!isset($this->_cell_lengths[$i])) {
$this->_cell_lengths[$i] = 0;
}
$this->_cell_lengths[$i] = max($this->_cell_lengths[$i],
$this->_strlen($row[$i]));
}
}
|
Calculates the maximum length for each column of a row.
@param array $row The row data.
@return void
|
_calculateCellLengths
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _calculateRowHeight($row_number, $row)
{
if (!isset($this->_row_heights[$row_number])) {
$this->_row_heights[$row_number] = 1;
}
// Do not process horizontal rule rows.
if ($row === CONSOLE_TABLE_HORIZONTAL_RULE) {
return;
}
for ($i = 0, $c = count($row); $i < $c; ++$i) {
$lines = preg_split('/\r?\n|\r/', $row[$i]);
$this->_row_heights[$row_number] = max($this->_row_heights[$row_number],
count($lines));
}
}
|
Calculates the maximum height for all columns of a row.
@param integer $row_number The row number.
@param array $row The row data.
@return void
|
_calculateRowHeight
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _strlen($str)
{
static $mbstring, $utf8;
// Strip ANSI color codes if requested.
if ($this->_ansiColor) {
$str = Console_Color::strip($str);
}
// Cache expensive function_exists() calls.
if (!isset($mbstring)) {
$mbstring = function_exists('mb_strlen');
}
if (!isset($utf8)) {
$utf8 = function_exists('utf8_decode');
}
if ($utf8 &&
($this->_charset == strtolower('utf-8') ||
$this->_charset == strtolower('utf8'))) {
return strlen(utf8_decode($str));
}
if ($mbstring) {
return mb_strlen($str, $this->_charset);
}
return strlen($str);
}
|
Returns the character length of a string.
@param string $str A multibyte or singlebyte string.
@return integer The string length.
|
_strlen
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _substr($string, $start, $length = null)
{
static $mbstring;
// Cache expensive function_exists() calls.
if (!isset($mbstring)) {
$mbstring = function_exists('mb_substr');
}
if (is_null($length)) {
$length = $this->_strlen($string);
}
if ($mbstring) {
$ret = @mb_substr($string, $start, $length, $this->_charset);
if (!empty($ret)) {
return $ret;
}
}
return substr($string, $start, $length);
}
|
Returns part of a string.
@param string $string The string to be converted.
@param integer $start The part's start position, zero based.
@param integer $length The part's length.
@return string The string's part.
|
_substr
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
function _strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT)
{
$mb_length = $this->_strlen($input);
$sb_length = strlen($input);
$pad_length = $this->_strlen($pad);
/* Return if we already have the length. */
if ($mb_length >= $length) {
return $input;
}
/* Shortcut for single byte strings. */
if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
return str_pad($input, $length, $pad, $type);
}
switch ($type) {
case STR_PAD_LEFT:
$left = $length - $mb_length;
$output = $this->_substr(str_repeat($pad, ceil($left / $pad_length)),
0, $left, $this->_charset) . $input;
break;
case STR_PAD_BOTH:
$left = floor(($length - $mb_length) / 2);
$right = ceil(($length - $mb_length) / 2);
$output = $this->_substr(str_repeat($pad, ceil($left / $pad_length)),
0, $left, $this->_charset) .
$input .
$this->_substr(str_repeat($pad, ceil($right / $pad_length)),
0, $right, $this->_charset);
break;
case STR_PAD_RIGHT:
$right = $length - $mb_length;
$output = $input .
$this->_substr(str_repeat($pad, ceil($right / $pad_length)),
0, $right, $this->_charset);
break;
}
return $output;
}
|
Returns a string padded to a certain length with another string.
This method behaves exactly like str_pad but is multibyte safe.
@param string $input The string to be padded.
@param integer $length The length of the resulting string.
@param string $pad The string to pad the input string with. Must
be in the same charset like the input string.
@param const $type The padding type. One of STR_PAD_LEFT,
STR_PAD_RIGHT, or STR_PAD_BOTH.
@return string The padded string.
|
_strpad
|
php
|
tombenner/wp-mvc
|
core/console/table.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/console/table.php
|
MIT
|
static function link($text, $url, $options=array(), $confirm_message='') {
if (is_array($url)) {
$url = MvcRouter::public_url($url);
}
$defaults = array(
'href' => $url,
'title' => $text
);
$options = array_merge($defaults, $options);
if (!empty($options['confirm'])) {
$confirm_message = $options['confirm'];
unset($options['confirm']);
}
if ($confirm_message) {
$confirm_message = str_replace("'", "\'", $confirm_message);
$confirm_message = str_replace('"', '\"', $confirm_message);
$options['onclick'] = "return confirm('{$confirm_message}');";
}
$attributes_html = self::attributes_html($options, 'a');
$html = '<a'.$attributes_html.'>'.$text.'</a>';
return $html;
}
|
Creates an html link
@param string $text - title of link
@param mixed $url - string path or array of URL parameters i.e. [controller => ..., action => ..., id => ...]
@param array $options - array of HTML attributes
@param string $confirm_message - javascript confirmation message
@return string - string <a /> element
|
link
|
php
|
tombenner/wp-mvc
|
core/helpers/mvc_html_helper.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/helpers/mvc_html_helper.php
|
MIT
|
public function controllers($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->destroy_controllers($plugin, $name);
}
|
Deletes controller source files
wpmvc destroy <plugin> <resource>
@param type $args
|
controllers
|
php
|
tombenner/wp-mvc
|
core/shells/destroy_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/destroy_shell.php
|
MIT
|
public function model($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->destroy_model($plugin, $name);
}
|
Deletes model source files
wpmvc destroy <plugin> <resource>
@param type $args
|
model
|
php
|
tombenner/wp-mvc
|
core/shells/destroy_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/destroy_shell.php
|
MIT
|
public function scaffold($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->destroy_controllers($plugin, $name);
$this->destroy_model($plugin, $name);
$this->destroy_views($plugin, $name);
}
|
Deletes model, controller, and view files for a resource
wpmvc destroy <plugin> <resource>
@param type $args
|
scaffold
|
php
|
tombenner/wp-mvc
|
core/shells/destroy_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/destroy_shell.php
|
MIT
|
public function views($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->destroy_views($plugin, $name);
}
|
Deletes view source files for a resource
wpmvc destroy views <plugin> <resource>
@param type $args
|
views
|
php
|
tombenner/wp-mvc
|
core/shells/destroy_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/destroy_shell.php
|
MIT
|
public function widget($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->destroy_widget($plugin, $name);
}
|
Delete a generated widget
@param mixed $args
|
widget
|
php
|
tombenner/wp-mvc
|
core/shells/destroy_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/destroy_shell.php
|
MIT
|
public function plugin($args) {
if (empty($args[0])) {
MvcError::fatal('Please specify a name for the plugin (e.g. "wpmvc generate plugin MyPlugin").');
}
$plugin = $args[0];
$this->generate_app($plugin);
}
|
Generate a MVC Plugin.
wpmvc generate plugin <plugin>
@param mixed $args
|
plugin
|
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 controllers($args) {
list($plugin, $name) = $this->get_plugin_model_args($args);
$this->generate_controllers($plugin, $name);
}
|
Generate controller and admin controller:
wpmvc generate controllers <plugin> <name>
@param mixed $args
|
controllers
|
php
|
tombenner/wp-mvc
|
core/shells/generate_shell.php
|
https://github.com/tombenner/wp-mvc/blob/master/core/shells/generate_shell.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.