-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit add6cae
Showing
27 changed files
with
4,119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) 2013 Jason Morriss | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Cisco Identity Engine REST Client | ||
|
||
Interface with the Cisco Identity Engine REST API. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "lifo/php-cisco-ise", | ||
"description": "Cisco Identity Services Engine REST API Client", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Jason Morriss", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { "Lifo\\CiscoISE\\": "src" } | ||
}, | ||
"require": { | ||
"php": ">=7.1", | ||
"ext-simplexml": "*", | ||
"symfony/property-access": "^3.0 || ^4.0 || ^5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="WEB_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$" /> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
|
||
namespace Lifo\CiscoISE; | ||
|
||
|
||
use JsonSerializable; | ||
|
||
abstract class AbstractListObject implements ObjectInterface, ObjectListInterface, JsonSerializable | ||
{ | ||
protected array $list = []; | ||
|
||
public function __construct(?array $from = null) | ||
{ | ||
if ($from) self::createFrom($from, $this); | ||
} | ||
|
||
public static function createFrom($from, $dest = null): self | ||
{ | ||
$dest ??= new static(); | ||
if (!is_array($from)) return $dest; | ||
foreach ($from as $item) { | ||
$dest->add($item); | ||
} | ||
return $dest; | ||
} | ||
|
||
public function mapPropToKey(string $prop): string | ||
{ | ||
return $prop; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return $this->list; | ||
} | ||
|
||
public function jsonSerialize() | ||
{ | ||
return $this->toArray(); | ||
} | ||
|
||
/** | ||
* Add an item to the list | ||
* | ||
* @param string $item | ||
* | ||
* @return $this | ||
*/ | ||
public function add($item): self | ||
{ | ||
if (!$this->exists($item)) { | ||
$this->list[] = $item; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Remove an item from the list | ||
* | ||
* @param string $item | ||
* | ||
* @return $this | ||
*/ | ||
public function remove($item): self | ||
{ | ||
$this->list = array_values(array_filter($this->list, fn($ele) => $ele !== $item)); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Returns true if the item exists | ||
* | ||
* @param string $item | ||
* | ||
* @return bool | ||
*/ | ||
public function exists($item): bool | ||
{ | ||
return in_array($item, $this->list); | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return count($this->list); | ||
} | ||
|
||
public function first() | ||
{ | ||
if (!$this->list) return null; | ||
return $this->list[0]; | ||
} | ||
|
||
public function getId(): ?string | ||
{ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
|
||
namespace Lifo\CiscoISE; | ||
|
||
|
||
use Exception; | ||
use JsonSerializable; | ||
use Symfony\Component\PropertyAccess\PropertyAccess; | ||
|
||
abstract class AbstractObject implements ObjectInterface, JsonSerializable | ||
{ | ||
/** | ||
* AbstractObject constructor. | ||
* | ||
* @param object|array $from | ||
*/ | ||
public function __construct($from = null) | ||
{ | ||
if ($from) self::createFrom($from, $this); | ||
} | ||
|
||
public function getId(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function mapPropToKey(string $prop): string | ||
{ | ||
return $prop; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$ary = []; | ||
$props = get_object_vars($this); | ||
foreach ($props as $prop => $val) { | ||
$key = $this->mapPropToKey($prop); | ||
if ($val instanceof ObjectInterface) { | ||
$ary[$key] = $val->toArray(); | ||
} else { | ||
$ary[$key] = $val; | ||
} | ||
} | ||
return $ary; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return $this->toArray(); | ||
} | ||
|
||
/** | ||
* @param mixed $from | ||
* @param mixed $dest | ||
* | ||
* @return self | ||
*/ | ||
public static function createFrom($from, $dest = null): self | ||
{ | ||
$dest ??= new static(); | ||
if (is_array($from)) $from = (object)$from; | ||
$props = get_object_vars($from); | ||
$accessor = PropertyAccess::createPropertyAccessor(); | ||
foreach ($props as $prop => $value) { | ||
try { | ||
if (is_object($value)) { | ||
// some server objects are lowercase; must uppercase it for Class detection to work | ||
$cls = __NAMESPACE__ . '\\' . str_replace('setting', 'Setting', ucfirst($prop)); | ||
if (is_a($cls, ObjectInterface::class, true)) { | ||
$value = new $cls($value); | ||
} | ||
} | ||
if ($accessor->isWritable($dest, $prop)) { | ||
$accessor->setValue($dest, $prop, $value); | ||
} | ||
} catch (Exception $e) { | ||
continue; | ||
} | ||
} | ||
return $dest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
|
||
namespace Lifo\CiscoISE; | ||
|
||
abstract class AbstractResult | ||
{ | ||
protected CiscoISEClient $ise; | ||
protected object $result; | ||
|
||
public function __construct(object $result, CiscoISEClient $ise) | ||
{ | ||
$this->result = $result; | ||
$this->ise = $ise; | ||
} | ||
|
||
/** | ||
* Return the RAW result response from the server. | ||
* | ||
* @return object | ||
*/ | ||
protected function getResult() | ||
{ | ||
return $this->result; | ||
} | ||
|
||
/** | ||
* @return CiscoISEClient | ||
*/ | ||
protected function getISEClient() | ||
{ | ||
return $this->ise; | ||
} | ||
|
||
/** | ||
* @param string $var | ||
* @param object $obj | ||
* @param mixed $default | ||
* | ||
* @return mixed | ||
*/ | ||
protected function extractProperty(string $var, object $obj, $default = null) | ||
{ | ||
if (property_exists($obj, $var)) { | ||
return $obj->$var; | ||
} | ||
return $default; | ||
} | ||
|
||
} |
Oops, something went wrong.