private function toArrayFromModel(Disk\Internals\Model $model) { $entity = null; if ($model instanceof Disk\Storage) { $entity = new Entity\Storage(); } elseif ($model instanceof Disk\File) { $entity = new Entity\Folder(); } elseif ($model instanceof Disk\Folder) { $entity = new Entity\File(); } elseif ($model instanceof Disk\AttachedObject) { $entity = new Entity\AttachedObject(); } else { throw new RestException('Unknown object ' . get_class($model)); } $toArray = array_intersect_key($model->toArray(), $entity->getFieldsForShow()); foreach ($entity->getFieldsForMap() as $fieldName => $modifiers) { if (!isset($toArray[$fieldName])) { continue; } $toArray[$fieldName] = call_user_func_array($modifiers['OUT'], array($toArray[$fieldName])); } unset($fieldName, $modifiers); if ($model instanceof Disk\File) { $toArray['DOWNLOAD_URL'] = \CRestUtil::getDownloadUrl(array('id' => $model->getId()), $this->restServer); if ($model->getStorage()->getProxyType() instanceof Disk\ProxyType\RestApp) { $toArray['DETAIL_URL'] = null; } else { $toArray['DETAIL_URL'] = $this->host . $this->urlManager->getPathFileDetail($model); } } elseif ($model instanceof Disk\Folder) { if ($model->getStorage()->getProxyType() instanceof Disk\ProxyType\RestApp) { $toArray['DETAIL_URL'] = null; } else { $toArray['DETAIL_URL'] = $this->host . $this->urlManager->getPathInListing($model) . $model->getName(); } } elseif ($model instanceof Disk\AttachedObject) { $toArray['DOWNLOAD_URL'] = $this->host . $this->urlManager->getUrlUfController('download', array('attachedId' => $model->getId(), 'auth' => $this->restServer->getAuth())); $toArray['NAME'] = $model->getFile()->getName(); $toArray['SIZE'] = $model->getFile()->getSize(); } return $toArray; }