/** * Returns the value of a property. * * @param string $name * @return mixed|null */ protected function getProperty($name) { if ($this->properties->offsetExists($name)) { return $this->properties->offsetGet($name); } return null; }
/** * Populate data container * * @param Array|null $data Data to populate container * @param Array|scalar|null $param Request parameters. Used to fetch data from DB when $data is empty. * If scalar data provided - used as prmary key value * @throws Advertikon\Exception\InvalidArgument On on unsupported argument type */ protected function _initData($data, $param) { if ($data) { if (is_array($data)) { $data = new ArrayObject($data); } if (is_a($data, 'Zend\\Stdlib\\ArrayObject')) { unset($data[$this->_resource->getPrimaryKey()]); $this->_data = $data; } else { throw new InvalidArgument('Unsupported argument type for Model data initiation', __METHOD__); } } elseif ($param) { if (is_array($param) || is_a($param, 'Zend\\Stdlib\\ArrayObject')) { if (is_array($param)) { $param = new ArrayObject($param); } if (!$param->count()) { $this->_data = new ArrayObject(); } else { $this->_load($param); } } elseif (is_scalar($param)) { $key = $this->_resource->getPrimaryKey(); $arr = new ArrayObject(); $arr[$key] = $param; $this->_load($arr); } else { throw new InvalidArgument('Invalid format of query parameter', __METHOD__); } } else { $this->_data = new ArrayObject(); } }
public function testExchangeArrayTestAssetIterator() { $ar = $this->getMockForAbstractClass(AbstractCollection::class); $ar->expects($this->atLeastOnce())->method('validateValue')->withAnyParameters()->willReturn(null); $ar->exchangeArray(new ArrayObjectIterator(['foo' => 'bar'])); // make sure it does what php array object does: $ar2 = new \ArrayObject(); $ar2->exchangeArray(new ArrayObjectIterator(['foo' => 'bar'])); $this->assertEquals($ar2->getArrayCopy(), $ar->getArrayCopy()); }
/** * Append an entity to the collection. * * @param EntityInterface $entity * @throws Exception\InvalidEntityException */ public function append(EntityInterface $entity) { if (!$this->isAllowed($entity)) { throw new Exception\InvalidEntityException(sprintf("Invalid entity '%s' for collection '%s'", get_class($entity), get_class($this))); } $this->entities->append($entity); }
/** * TestRecord constructor. * @param $adapter * @param $array */ public function __construct(Adapter $adapter) { // Allow accessing properties as either array keys or object properties: parent::__construct(array(), ArrayObject::ARRAY_AS_PROPS); // http://stackoverflow.com/questions/14610307/spl-arrayobject-arrayobjectstd-prop-list $this->adapter = $adapter; }
/** * @param string $className * @return Datagrid */ public function create($className) { /** @var \Doctrine\ORM\EntityManager $entityManager */ $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $metadata = $entityManager->getClassMetadata($className); $reflection = $metadata->getReflectionClass(); $datagridSpec = new ArrayObject(array('className' => $className, 'primaryKey' => $metadata->getSingleIdentifierFieldName(), 'name' => array('singular' => '', 'plural' => ''), 'defaultSort' => null, 'headerColumns' => array(), 'searchColumns' => array(), 'suggestColumns' => array())); $reader = new AnnotationReader(); foreach ($reader->getClassAnnotations($reflection) as $annotation) { $params = compact('datagridSpec', 'annotation'); $this->getEventManager()->trigger('discoverTitle', $this, $params); } foreach ($reflection->getProperties() as $property) { foreach ($reader->getPropertyAnnotations($property) as $annotation) { $params = compact('datagridSpec', 'annotation', 'property'); $this->getEventManager()->trigger('configureColumn', $this, $params); } } foreach ($reflection->getMethods() as $method) { foreach ($reader->getMethodAnnotations($method) as $annotation) { $params = compact('datagridSpec', 'annotation', 'method'); $this->getEventManager()->trigger('configureColumn', $this, $params); } } $this->datagrids[$className] = new Datagrid($entityManager, $datagridSpec->getArrayCopy()); return $this->datagrids[$className]; }
/** * Delete constant from constant list * * @param string $constant * * @return bool */ public function deleteConstant($constant) { if (($index = array_search($constant, $this->constants->getArrayCopy())) !== false) { $this->constants->offsetUnset($index); } return $index !== false; }
/** * @return \Zend\Http\Response|ViewModel */ public function detailAction() { $id = (int) $this->params()->fromRoute('id', 0); $helper = new AttendanceBoardHelper(); $form = $helper->getForm($this->staffCombo()); $attendance = $this->attendanceTable()->getAttendance($id); if (!$attendance) { $attendance = new ArrayObject(array('attendanceId' => $id)); } else { $attendance = new ArrayObject($attendance->getArrayCopy()); } $attendance['hour'] = (int) date('H', time()); $attendance['minute'] = round((int) date('i', time()) / 5); if ($attendance['hour'] > 12 && strlen($attendance['inTime']) > 1) { $attendance['type'] = 'O'; } else { $attendance['type'] = 'I'; } $form->bind($attendance); $request = $this->getRequest(); if ($request->isPost()) { $post_data = $request->getPost(); $form->setData($post_data); $form->setInputFilter($helper->getInputFilter()); if ($form->isValid()) { $newData = $this->attendanceTable()->getAttendanceByStaff($attendance['staffId'], $attendance['attendanceDate']); if (!$newData) { $newData = new Attendance(); $newData->exchangeArray($attendance->getArrayCopy()); } $time = sprintf('%02d:%02d:00', $attendance['hour'], $attendance['minute'] * 5); if ($attendance['type'] == 'I') { $newData->setInTime($time); } else { $newData->setOutTime($time); } $this->attendanceTable()->saveAttendance($newData); $this->flashMessenger()->addSuccessMessage('Save successful'); return $this->redirect()->toRoute('hr_attendance'); } } return new ViewModel(array('form' => $form, 'id' => $id)); }
/** * @param mixed $key * @param mixed $value * @throws Exception\RuntimeException */ public function offsetSet($key, $value) { if ($this->isImmutable()) { throw new Exception\RuntimeException(sprintf('Cannot set key "%s" as storage is marked isImmutable', $key)); } if ($this->isLocked($key)) { throw new Exception\RuntimeException(sprintf('Cannot set key "%s" due to locking', $key)); } parent::offsetSet($key, $value); }
/** * Constructor * * Provide a name ('Default' if none provided) and a ManagerInterface instance. * * @param null|string $name * @param Manager $manager * @throws Exception\InvalidArgumentException */ public function __construct($name = 'Default', Manager $manager = null) { if (!preg_match('/^[a-z0-9][a-z0-9_\\\\]+$/i', $name)) { throw new Exception\InvalidArgumentException('Name passed to container is invalid; must consist of alphanumerics, backslashes and underscores only'); } $this->name = $name; $this->setManager($manager); // Create namespace parent::__construct([], ArrayObject::ARRAY_AS_PROPS); // Start session $this->getManager()->start(); }
/** * Constructor * * @param array $input * @param int $flags * @param string $iteratorClass * @return ArrayObject */ public function __construct($input = array(), $flags = self::STD_PROP_LIST, $iteratorClass = 'ArrayIterator') { parent::__construct($input, $flags, $iteratorClass); }
/** * {@inheritdoc} */ public function exchangeArray($data) { $oldData = parent::exchangeArray($data); try { $this->validateData($this->storage); } catch (\Exception $e) { $this->storage = $oldData; throw $e; } return $oldData; }
/** * @param ArrayObject $config * * @throws \Phpro\AnnotatedForms\Exception\RuntimeException */ protected function injectListeners(ArrayObject $config) { if (!$config->offsetExists('listeners') || !$config->offsetGet('listeners')) { return; } $listeners = $config->offsetGet('listeners'); foreach ($listeners as $index => $serviceKey) { $listener = $this->getServiceLocator()->get($serviceKey); if (!$listener instanceof ListenerAggregateInterface) { throw new RuntimeException(sprintf('Expected ListenerAggregateInterface for key "%s"', $serviceKey)); } $listeners[$index] = $listener; } $config->offsetSet('listeners', $listeners); }
public function testUksort() { $function = function ($a, $b) { $a = preg_replace('@^(a|an|the) @', '', $a); $b = preg_replace('@^(a|an|the) @', '', $b); return strcasecmp($a, $b); }; $ar = new ArrayObject(array('John' => 1, 'the Earth' => 2, 'an apple' => 3, 'a banana' => 4)); $sorted = $ar->getArrayCopy(); uksort($sorted, $function); $ar->uksort($function); $this->assertSame($sorted, $ar->getArrayCopy()); }
/** * getIterator * * @return array|\Traversable */ public function getIterator() { $a = new ArrayObject($this->toArray()); return $a->getIterator(); }
/** * Only allow Vector2D objects to be appended * * @param \Chippyash\Matrix\Vector\Vector2D $value * @return \Chippyash\Matrix\Vector\VectorSet $this * @throws \Chippyash\Matrix\Exceptions\VectorException */ public function append($value) { if (!$value instanceof Vector2D) { throw new VectorException('Append value is not a vector'); } parent::append($value); return $this; }
/** * @param string $name * @param mixed $default optional default value * @return mixed */ public function get($name, $default = null) { if (isset($this[$name])) { return parent::offsetGet($name); } return $default; }
/** * @param string $name * @param mixed $default optional default value * @return mixed */ public function get($name, $default = null) { if ($this->offsetExists($name)) { return parent::offsetGet($name); } return $default; }
/** * @param ArrayObject $associations * @param array $data * @return ArrayObject */ protected function stripEmptyAssociations(ArrayObject $associations, $data) { $associationsArray = $associations->getArrayCopy(); foreach ($associationsArray as $key => $association) { if (!$this->validateAssociationData($association, $data)) { unset($associationsArray[$key]); } } return new ArrayObject($associationsArray); }
/** * @param SmartServiceInterface $smartServiceInterface * @param ArrayObject $config * * @return $this */ private function injectQueryProvider(SmartServiceInterface $smartServiceInterface, ArrayObject $config) { if (!$smartServiceInterface instanceof QueryProviderAwareInterface) { return $this; } if ($config->offsetExists($this::CONFIG_OPTIONS) && count($config[$this::CONFIG_OPTIONS]) < 1) { return $this; } $options = $config[$this::CONFIG_OPTIONS]; if (!isset($options['query-provider'])) { return $this; } $queryProvider = $this->getServiceLocator()->get($options['query-provider']); $smartServiceInterface->setQueryProvider($queryProvider); return $this; }
/** * @param $associations ArrayObject * @param $data array * * @return mixed array */ protected function stripEmptyAssociations(ArrayObject $associations, $data) { $associationsArray = $associations->getArrayCopy(); foreach ($associationsArray as $key => $association) { if (!(array_key_exists($association, $data) && !empty($data[$association]) && (is_array($data[$association]) || $data[$association] instanceof \Traversable))) { unset($associationsArray[$key]); } } return new ArrayObject($associationsArray); }